Skip to content

Commit 57cacfb

Browse files
bhearsumwilldurand
andauthored
Support dlsource as an attribution parameter (fixes #159) (#162)
Co-authored-by: William Durand <[email protected]>
1 parent df52c8f commit 57cacfb

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

attributioncode/validator.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var validAttributionKeys = map[string]bool{
3838
"visit_id": true, // https://bugzilla.mozilla.org/show_bug.cgi?id=1677497
3939
"session_id": true, // https://bugzilla.mozilla.org/show_bug.cgi?id=1809120
4040
"client_id": true, // Alias of `visit_id`.
41+
"dlsource": true,
4142
}
4243

4344
// If any of these are not set in the incoming payload, they will be set to '(not set)'
@@ -63,16 +64,17 @@ func generateDownloadToken() string {
6364

6465
// Code represents a valid attribution code
6566
type Code struct {
66-
Source string
67-
Medium string
68-
Campaign string
69-
Content string
70-
Experiment string
71-
InstallerType string
72-
Variation string
73-
UA string
74-
ClientID string
75-
SessionID string
67+
Source string
68+
Medium string
69+
Campaign string
70+
Content string
71+
Experiment string
72+
InstallerType string
73+
Variation string
74+
UA string
75+
ClientID string
76+
SessionID string
77+
DownloadSource string
7678

7779
downloadToken string
7880

@@ -194,16 +196,17 @@ func (v *Validator) Validate(code, sig, refererHeader string) (*Code, error) {
194196
}
195197

196198
attributionCode := &Code{
197-
Source: vals.Get("source"),
198-
Medium: vals.Get("medium"),
199-
Campaign: vals.Get("campaign"),
200-
Content: vals.Get("content"),
201-
Experiment: vals.Get("experiment"),
202-
InstallerType: vals.Get("installer_type"),
203-
Variation: vals.Get("variation"),
204-
UA: vals.Get("ua"),
205-
ClientID: clientID,
206-
SessionID: vals.Get("session_id"),
199+
Source: vals.Get("source"),
200+
Medium: vals.Get("medium"),
201+
Campaign: vals.Get("campaign"),
202+
Content: vals.Get("content"),
203+
Experiment: vals.Get("experiment"),
204+
InstallerType: vals.Get("installer_type"),
205+
Variation: vals.Get("variation"),
206+
UA: vals.Get("ua"),
207+
ClientID: clientID,
208+
SessionID: vals.Get("session_id"),
209+
DownloadSource: vals.Get("dlsource"),
207210

208211
rawURLVals: vals,
209212
}

attributioncode/validator_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func TestValidateAttributionCode(t *testing.T) {
133133
"vid",
134134
"sid",
135135
},
136+
{
137+
"Y2FtcGFpZ249dGVzdGNhbXBhaWduJmNvbnRlbnQ9dGVzdGNvbnRlbnQmZXhwZXJpbWVudD1leHAxJmluc3RhbGxlcl90eXBlPWZ1bGwmbWVkaXVtPXRlc3RtZWRpdW0mc291cmNlPW1vemlsbGEuY29tJnRpbWVzdGFtcD0xNjcwMzU4ODE0JnZhcmlhdGlvbj12YXIxJmRsc291cmNlPW1vem9yZw..", // campaign=testcampaign&content=testcontent&experiment=exp1&installer_type=full&medium=testmedium&source=mozilla.com&timestamp=1670358814&variation=var1&dlsource=mozorg
138+
"campaign%3Dtestcampaign%26content%3Dtestcontent%26dlsource%3Dmozorg%26dltoken%3D__DL_TOKEN__%26experiment%3Dexp1%26installer_type%3Dfull%26medium%3Dtestmedium%26source%3Dmozilla.com%26variation%3Dvar1",
139+
"",
140+
"",
141+
"",
142+
},
136143
}
137144
for _, c := range validCodes {
138145
code, err := v.Validate(c.In, "", c.RefererHeader)

testing/stubtestclient/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
variation string
2525
clientID string
2626
sessionID string
27+
dlsource string
2728

2829
lang string
2930
os string
@@ -60,6 +61,7 @@ func init() {
6061
flag.StringVar(&installerType, "installer_type", "full", "installer_type")
6162
flag.StringVar(&clientID, "client_id", "cid", "client_id")
6263
flag.StringVar(&sessionID, "session_id", "sid", "session_id")
64+
flag.StringVar(&dlsource, "dlsource", "testmozorg", "dlsource")
6365

6466
flag.StringVar(&lang, "lang", "en-US", "")
6567
flag.StringVar(&os, "os", "win", "")

0 commit comments

Comments
 (0)