-
Notifications
You must be signed in to change notification settings - Fork 43
/
click.go
110 lines (106 loc) · 2.34 KB
/
click.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package track
import (
"net/url"
"github.com/bububa/oceanengine/marketing-api/model"
)
// DEFAULT_CLICK_FIELDS 默认点击检测字段
var DEFAULT_CLICK_FIELDS = []string{
"request_id",
"aid",
"advertiser_id",
"cid",
"campaign_id",
"ctype",
"csite",
"imei",
"idfa",
"android_id",
"oaid",
"os",
"mac",
"mac1",
"ip",
"ua",
"geo",
"ts",
"track_id",
"callback",
"callback_url",
"model",
"union_site",
"caid1",
}
// Click 生成击检测链接
func Click(baseUrl string, fields []string, adVersion model.AdVersion) string {
if fields == nil {
fields = DEFAULT_CLICK_FIELDS
}
parsedUrl, _ := url.Parse(baseUrl)
values := parsedUrl.Query()
for _, field := range fields {
switch field {
case "request_id":
values.Set("request_id", "__REQUEST_ID__")
case "aid":
if adVersion == model.AdVersion_2 {
values.Set("aid", "__PROMOTION_ID__")
} else {
values.Set("aid", "__AID__")
}
case "advertiser_id":
values.Set("advertiser_id", "__ADVERTISER_ID__")
case "cid":
if adVersion != model.AdVersion_2 {
values.Set("cid", "__CID__")
}
case "campaign_id":
if adVersion == model.AdVersion_2 {
values.Set("campaign_id", "__PROJECT_ID__")
} else {
values.Set("campaign_id", "__CAMPAIGN_ID__")
}
case "ctype":
values.Set("ctype", "__CTYPE__")
case "csite":
values.Set("csite", "__CSITE__")
case "imei":
values.Set("imei", "__IMEI__")
case "idfa":
values.Set("idfa", "__IDFA__")
case "android_id":
values.Set("android_id", "__ANDROIDID__")
case "oaid":
values.Set("oaid", "__OAID__")
case "os":
values.Set("os", "__OS__")
case "mac":
values.Set("mac", "__MAC__")
case "mac1":
values.Set("mac1", "__MAC1__")
case "ip":
values.Set("ip", "__IP__")
case "ua":
values.Set("ua", "__UA__")
case "geo":
values.Set("geo", "__GEO__")
case "ts":
values.Set("ts", "__TS__")
case "track_id":
values.Set("track_id", "__TRACK_ID__")
case "callback":
values.Set("callback", "__CALLBACK_PARAM__")
case "callback_url":
values.Set("callback_url", "__CALLBACK_URL__")
case "model":
values.Set("model", "__MODEL__")
case "union_site":
values.Set("union_site", "__UNION_SITE__")
case "caid1":
values.Set("caid1", "__CAID1__")
case "caid2":
values.Set("caid2", "__CAID2__")
}
}
parsedUrl.RawQuery = values.Encode()
return parsedUrl.String()
}