@shware/analytics 8.9.0 → 8.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attribution/index.cjs +275 -0
- package/dist/attribution/index.cjs.map +1 -0
- package/dist/attribution/index.d.cts +108 -0
- package/dist/attribution/index.d.cts.map +1 -0
- package/dist/attribution/index.d.mts +108 -0
- package/dist/attribution/index.d.mts.map +1 -0
- package/dist/attribution/index.mjs +258 -0
- package/dist/attribution/index.mjs.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/attribution/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the
|
|
5
|
+
* dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with
|
|
6
|
+
* the product is its own hostnames (referrer exclusions) and its landing-page convention.
|
|
7
|
+
*/
|
|
8
|
+
/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */
|
|
9
|
+
const DIRECT_CHANNEL = "(direct)";
|
|
10
|
+
/** The medium of a direct session. */
|
|
11
|
+
const NO_MEDIUM = "(none)";
|
|
12
|
+
/** The medium of a tagged link that named a source but no medium. */
|
|
13
|
+
const MEDIUM_NOT_SET = "(not set)";
|
|
14
|
+
/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */
|
|
15
|
+
const CHANNELS = [
|
|
16
|
+
"meta",
|
|
17
|
+
"google",
|
|
18
|
+
"dv360",
|
|
19
|
+
"microsoft",
|
|
20
|
+
"tiktok",
|
|
21
|
+
"reddit",
|
|
22
|
+
"linkedin",
|
|
23
|
+
"snapchat",
|
|
24
|
+
"x",
|
|
25
|
+
"kakao",
|
|
26
|
+
"yandex",
|
|
27
|
+
"yahoo",
|
|
28
|
+
"duckduckgo",
|
|
29
|
+
"baidu",
|
|
30
|
+
"ecosia",
|
|
31
|
+
"naver",
|
|
32
|
+
"brave",
|
|
33
|
+
"pinterest",
|
|
34
|
+
"youtube",
|
|
35
|
+
"referral_program"
|
|
36
|
+
];
|
|
37
|
+
/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
|
|
38
|
+
const CHANNEL_GROUPS = [
|
|
39
|
+
"direct",
|
|
40
|
+
"paid_search",
|
|
41
|
+
"paid_social",
|
|
42
|
+
"paid_other",
|
|
43
|
+
"display",
|
|
44
|
+
"organic_search",
|
|
45
|
+
"organic_social",
|
|
46
|
+
"organic_video",
|
|
47
|
+
"referral",
|
|
48
|
+
"email",
|
|
49
|
+
"affiliate",
|
|
50
|
+
"unassigned"
|
|
51
|
+
];
|
|
52
|
+
/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
|
|
53
|
+
const SOURCE_ALIASES = {
|
|
54
|
+
fb: "meta",
|
|
55
|
+
ig: "meta",
|
|
56
|
+
an: "meta",
|
|
57
|
+
msg: "meta",
|
|
58
|
+
facebook: "meta",
|
|
59
|
+
instagram: "meta",
|
|
60
|
+
bing: "microsoft",
|
|
61
|
+
twitter: "x"
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Which click id belongs to which channel, in priority order. Every key is a field this SDK
|
|
65
|
+
* collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
|
|
66
|
+
* browser ids, present with or without a click.
|
|
67
|
+
*/
|
|
68
|
+
const CLICK_ID_CHANNELS = [
|
|
69
|
+
["fbclid", "meta"],
|
|
70
|
+
["fbc", "meta"],
|
|
71
|
+
["gclid", "google"],
|
|
72
|
+
["gbraid", "google"],
|
|
73
|
+
["wbraid", "google"],
|
|
74
|
+
["gad_source", "google"],
|
|
75
|
+
["gad_campaignid", "google"],
|
|
76
|
+
["dclid", "dv360"],
|
|
77
|
+
["msclkid", "microsoft"],
|
|
78
|
+
["ttclid", "tiktok"],
|
|
79
|
+
["rdt_cid", "reddit"],
|
|
80
|
+
["li_fat_id", "linkedin"],
|
|
81
|
+
["sccid", "snapchat"],
|
|
82
|
+
["twclid", "x"],
|
|
83
|
+
["ko_click_id", "kakao"],
|
|
84
|
+
["yclid", "yandex"]
|
|
85
|
+
];
|
|
86
|
+
/**
|
|
87
|
+
* A landing page reserved for one channel's ads, for ads that lost their parameters:
|
|
88
|
+
* `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
|
|
89
|
+
* that names its landing pages differently replaces this.
|
|
90
|
+
*/
|
|
91
|
+
const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
|
|
92
|
+
/**
|
|
93
|
+
* Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
|
|
94
|
+
* with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
|
|
95
|
+
* its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
|
|
96
|
+
* never an open tail, so `google.com.evil.io` is not Google.
|
|
97
|
+
*/
|
|
98
|
+
const REFERRER_SITES = [
|
|
99
|
+
[
|
|
100
|
+
"google",
|
|
101
|
+
"organic",
|
|
102
|
+
String.raw`(^|\.)google\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"microsoft",
|
|
106
|
+
"organic",
|
|
107
|
+
String.raw`(^|\.)bing\.com$`
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"yahoo",
|
|
111
|
+
"organic",
|
|
112
|
+
String.raw`(^|\.)yahoo\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
"duckduckgo",
|
|
116
|
+
"organic",
|
|
117
|
+
String.raw`(^|\.)duckduckgo\.com$`
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"baidu",
|
|
121
|
+
"organic",
|
|
122
|
+
String.raw`(^|\.)baidu\.com$`
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
"yandex",
|
|
126
|
+
"organic",
|
|
127
|
+
String.raw`(^|\.)yandex\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
"ecosia",
|
|
131
|
+
"organic",
|
|
132
|
+
String.raw`(^|\.)ecosia\.org$`
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"naver",
|
|
136
|
+
"organic",
|
|
137
|
+
String.raw`(^|\.)naver\.com$`
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
"brave",
|
|
141
|
+
"organic",
|
|
142
|
+
String.raw`^search\.brave\.com$`
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
"meta",
|
|
146
|
+
"social",
|
|
147
|
+
String.raw`(^|\.)(facebook\.com|instagram\.com|fb\.com|threads\.net)$`
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
"x",
|
|
151
|
+
"social",
|
|
152
|
+
String.raw`(^|\.)(twitter\.com|x\.com|t\.co)$`
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
"linkedin",
|
|
156
|
+
"social",
|
|
157
|
+
String.raw`(^|\.)(linkedin\.com|lnkd\.in)$`
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"reddit",
|
|
161
|
+
"social",
|
|
162
|
+
String.raw`(^|\.)reddit\.com$`
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
"tiktok",
|
|
166
|
+
"social",
|
|
167
|
+
String.raw`(^|\.)tiktok\.com$`
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
"pinterest",
|
|
171
|
+
"social",
|
|
172
|
+
String.raw`(^|\.)pinterest\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
"snapchat",
|
|
176
|
+
"social",
|
|
177
|
+
String.raw`(^|\.)snapchat\.com$`
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
"youtube",
|
|
181
|
+
"video",
|
|
182
|
+
String.raw`(^|\.)(youtube\.com|youtu\.be)$`
|
|
183
|
+
]
|
|
184
|
+
];
|
|
185
|
+
/**
|
|
186
|
+
* Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
|
|
187
|
+
* visitor is bounced through and back from, and the local dev host. A product appends its own
|
|
188
|
+
* hostnames — a session that starts from an internal link after the session timeout refers to
|
|
189
|
+
* them. POSIX regular expressions over the lower-cased host.
|
|
190
|
+
*/
|
|
191
|
+
const REFERRERS_NOT_A_TOUCH = [
|
|
192
|
+
String.raw`^localhost(:|$)`,
|
|
193
|
+
String.raw`(^|\.)stripe\.com$`,
|
|
194
|
+
String.raw`^(pay|accounts)\.google\.com$`,
|
|
195
|
+
String.raw`^(appleid|apps)\.apple\.com$`,
|
|
196
|
+
String.raw`^play\.google\.com$`,
|
|
197
|
+
String.raw`^login\.microsoftonline\.com$`
|
|
198
|
+
];
|
|
199
|
+
/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
|
|
200
|
+
const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
|
|
201
|
+
const DISPLAY_MEDIUMS = [
|
|
202
|
+
"display",
|
|
203
|
+
"banner",
|
|
204
|
+
"expandable",
|
|
205
|
+
"interstitial"
|
|
206
|
+
];
|
|
207
|
+
const EMAIL_MEDIUMS = [
|
|
208
|
+
"email",
|
|
209
|
+
"e-mail",
|
|
210
|
+
"e_mail",
|
|
211
|
+
"e mail"
|
|
212
|
+
];
|
|
213
|
+
/** Where a touch came from: a tracked session, or a report by the user or staff. */
|
|
214
|
+
const TOUCH_SOURCES = ["tracked", "reported"];
|
|
215
|
+
/**
|
|
216
|
+
* How a reported touch was learned:
|
|
217
|
+
* - survey: the user answered "how did you hear about us" (onboarding, checkout)
|
|
218
|
+
* - promo_code: the user redeemed a code that belongs to a channel
|
|
219
|
+
* - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
|
|
220
|
+
* - manual: staff recorded what a customer told them
|
|
221
|
+
*/
|
|
222
|
+
const REPORTED_TOUCH_KINDS = [
|
|
223
|
+
"survey",
|
|
224
|
+
"promo_code",
|
|
225
|
+
"phone",
|
|
226
|
+
"manual"
|
|
227
|
+
];
|
|
228
|
+
/**
|
|
229
|
+
* How much a touch is worth against another when attribution has to choose between sessions;
|
|
230
|
+
* lower wins, and the latest wins among equals. Derived in the views, never stored, so
|
|
231
|
+
* renumbering is a view regeneration.
|
|
232
|
+
*
|
|
233
|
+
* This ranks touches against each other. Within one session the rules that name its channel have
|
|
234
|
+
* their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
|
|
235
|
+
* and the first that says something wins; the session's priority is then the tier of that rule.
|
|
236
|
+
* So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
|
|
237
|
+
* later one is credited, while one session carrying both is named by its utm.
|
|
238
|
+
*/
|
|
239
|
+
const TOUCH_PRIORITY = {
|
|
240
|
+
/** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
|
|
241
|
+
campaign: 1,
|
|
242
|
+
/** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
|
|
243
|
+
verified: 1,
|
|
244
|
+
/** the browser said where the visitor came from; nobody chose it */
|
|
245
|
+
referrer: 2,
|
|
246
|
+
/** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
|
|
247
|
+
claimed: 3
|
|
248
|
+
};
|
|
249
|
+
/** Which reported kinds are staff facts and which are the user's claims. */
|
|
250
|
+
const REPORTED_TOUCH_PRIORITY = {
|
|
251
|
+
phone: TOUCH_PRIORITY.verified,
|
|
252
|
+
manual: TOUCH_PRIORITY.verified,
|
|
253
|
+
survey: TOUCH_PRIORITY.claimed,
|
|
254
|
+
promo_code: TOUCH_PRIORITY.claimed
|
|
255
|
+
};
|
|
256
|
+
//#endregion
|
|
257
|
+
exports.AD_LANDING_PAGE = AD_LANDING_PAGE;
|
|
258
|
+
exports.CHANNELS = CHANNELS;
|
|
259
|
+
exports.CHANNEL_GROUPS = CHANNEL_GROUPS;
|
|
260
|
+
exports.CLICK_ID_CHANNELS = CLICK_ID_CHANNELS;
|
|
261
|
+
exports.DIRECT_CHANNEL = DIRECT_CHANNEL;
|
|
262
|
+
exports.DISPLAY_MEDIUMS = DISPLAY_MEDIUMS;
|
|
263
|
+
exports.EMAIL_MEDIUMS = EMAIL_MEDIUMS;
|
|
264
|
+
exports.MEDIUM_NOT_SET = MEDIUM_NOT_SET;
|
|
265
|
+
exports.NO_MEDIUM = NO_MEDIUM;
|
|
266
|
+
exports.PAID_MEDIUM = PAID_MEDIUM;
|
|
267
|
+
exports.REFERRERS_NOT_A_TOUCH = REFERRERS_NOT_A_TOUCH;
|
|
268
|
+
exports.REFERRER_SITES = REFERRER_SITES;
|
|
269
|
+
exports.REPORTED_TOUCH_KINDS = REPORTED_TOUCH_KINDS;
|
|
270
|
+
exports.REPORTED_TOUCH_PRIORITY = REPORTED_TOUCH_PRIORITY;
|
|
271
|
+
exports.SOURCE_ALIASES = SOURCE_ALIASES;
|
|
272
|
+
exports.TOUCH_PRIORITY = TOUCH_PRIORITY;
|
|
273
|
+
exports.TOUCH_SOURCES = TOUCH_SOURCES;
|
|
274
|
+
|
|
275
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/attribution/index.ts"],"sourcesContent":["import type { AdvertisingInfo } from '../track/types';\n\n/**\n * The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the\n * dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with\n * the product is its own hostnames (referrer exclusions) and its landing-page convention.\n */\n\n/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */\nexport const DIRECT_CHANNEL = '(direct)';\n/** The medium of a direct session. */\nexport const NO_MEDIUM = '(none)';\n/** The medium of a tagged link that named a source but no medium. */\nexport const MEDIUM_NOT_SET = '(not set)';\n\n/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */\nexport const CHANNELS = [\n 'meta',\n 'google',\n 'dv360',\n 'microsoft',\n 'tiktok',\n 'reddit',\n 'linkedin',\n 'snapchat',\n 'x',\n 'kakao',\n 'yandex',\n 'yahoo',\n 'duckduckgo',\n 'baidu',\n 'ecosia',\n 'naver',\n 'brave',\n 'pinterest',\n 'youtube',\n /** the product's own referral programme: the session came through a member's link or code.\n * How a product recognises one (a `/refer/<code>` path, a code at sign-up) is its own rule. Not\n * `referral`: that word is the channel group of any outside site, and a channel of the same name\n * would be impossible to tell apart in queries. */\n 'referral_program',\n] as const;\n\nexport type Channel = (typeof CHANNELS)[number];\n\n/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */\nexport const CHANNEL_GROUPS = [\n 'direct',\n 'paid_search',\n 'paid_social',\n 'paid_other',\n 'display',\n 'organic_search',\n 'organic_social',\n 'organic_video',\n 'referral',\n 'email',\n 'affiliate',\n 'unassigned',\n] as const;\n\nexport type ChannelGroup = (typeof CHANNEL_GROUPS)[number];\n\n/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */\nexport const SOURCE_ALIASES = {\n fb: 'meta',\n ig: 'meta',\n an: 'meta',\n msg: 'meta',\n facebook: 'meta',\n instagram: 'meta',\n bing: 'microsoft',\n twitter: 'x',\n} as const satisfies Record<string, Channel>;\n\n/**\n * Which click id belongs to which channel, in priority order. Every key is a field this SDK\n * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel\n * browser ids, present with or without a click.\n */\nexport const CLICK_ID_CHANNELS = [\n ['fbclid', 'meta'],\n ['fbc', 'meta'],\n ['gclid', 'google'],\n ['gbraid', 'google'],\n ['wbraid', 'google'],\n ['gad_source', 'google'],\n ['gad_campaignid', 'google'],\n ['dclid', 'dv360'],\n ['msclkid', 'microsoft'],\n ['ttclid', 'tiktok'],\n ['rdt_cid', 'reddit'],\n ['li_fat_id', 'linkedin'],\n ['sccid', 'snapchat'],\n ['twclid', 'x'],\n ['ko_click_id', 'kakao'],\n ['yclid', 'yandex'],\n] as const satisfies readonly (readonly [keyof AdvertisingInfo, Channel])[];\n\n/**\n * A landing page reserved for one channel's ads, for ads that lost their parameters:\n * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product\n * that names its landing pages differently replaces this.\n */\nexport const AD_LANDING_PAGE = '^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)';\n\nexport type ReferrerMedium = 'organic' | 'social' | 'video';\n\n/**\n * Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,\n * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as\n * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),\n * never an open tail, so `google.com.evil.io` is not Google.\n */\nexport const REFERRER_SITES = [\n ['google', 'organic', String.raw`(^|\\.)google\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['microsoft', 'organic', String.raw`(^|\\.)bing\\.com$`],\n ['yahoo', 'organic', String.raw`(^|\\.)yahoo\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['duckduckgo', 'organic', String.raw`(^|\\.)duckduckgo\\.com$`],\n ['baidu', 'organic', String.raw`(^|\\.)baidu\\.com$`],\n ['yandex', 'organic', String.raw`(^|\\.)yandex\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['ecosia', 'organic', String.raw`(^|\\.)ecosia\\.org$`],\n ['naver', 'organic', String.raw`(^|\\.)naver\\.com$`],\n ['brave', 'organic', String.raw`^search\\.brave\\.com$`],\n ['meta', 'social', String.raw`(^|\\.)(facebook\\.com|instagram\\.com|fb\\.com|threads\\.net)$`],\n ['x', 'social', String.raw`(^|\\.)(twitter\\.com|x\\.com|t\\.co)$`],\n ['linkedin', 'social', String.raw`(^|\\.)(linkedin\\.com|lnkd\\.in)$`],\n ['reddit', 'social', String.raw`(^|\\.)reddit\\.com$`],\n ['tiktok', 'social', String.raw`(^|\\.)tiktok\\.com$`],\n ['pinterest', 'social', String.raw`(^|\\.)pinterest\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['snapchat', 'social', String.raw`(^|\\.)snapchat\\.com$`],\n ['youtube', 'video', String.raw`(^|\\.)(youtube\\.com|youtu\\.be)$`],\n] as const satisfies readonly (readonly [Channel, ReferrerMedium, string])[];\n\n/**\n * Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a\n * visitor is bounced through and back from, and the local dev host. A product appends its own\n * hostnames — a session that starts from an internal link after the session timeout refers to\n * them. POSIX regular expressions over the lower-cased host.\n */\nexport const REFERRERS_NOT_A_TOUCH = [\n String.raw`^localhost(:|$)`,\n String.raw`(^|\\.)stripe\\.com$`,\n String.raw`^(pay|accounts)\\.google\\.com$`,\n String.raw`^(appleid|apps)\\.apple\\.com$`,\n String.raw`^play\\.google\\.com$`,\n String.raw`^login\\.microsoftonline\\.com$`,\n] as const;\n\n/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */\nexport const PAID_MEDIUM = '^(.*cp.*|ppc|retargeting|paid.*)$';\nexport const DISPLAY_MEDIUMS = ['display', 'banner', 'expandable', 'interstitial'] as const;\nexport const EMAIL_MEDIUMS = ['email', 'e-mail', 'e_mail', 'e mail'] as const;\n\n/** Where a touch came from: a tracked session, or a report by the user or staff. */\nexport const TOUCH_SOURCES = ['tracked', 'reported'] as const;\nexport type TouchSource = (typeof TOUCH_SOURCES)[number];\n\n/**\n * How a reported touch was learned:\n * - survey: the user answered \"how did you hear about us\" (onboarding, checkout)\n * - promo_code: the user redeemed a code that belongs to a channel\n * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system\n * - manual: staff recorded what a customer told them\n */\nexport const REPORTED_TOUCH_KINDS = ['survey', 'promo_code', 'phone', 'manual'] as const;\nexport type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];\n\n/**\n * How much a touch is worth against another when attribution has to choose between sessions;\n * lower wins, and the latest wins among equals. Derived in the views, never stored, so\n * renumbering is a view regeneration.\n *\n * This ranks touches against each other. Within one session the rules that name its channel have\n * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —\n * and the first that says something wins; the session's priority is then the tier of that rule.\n * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the\n * later one is credited, while one session carrying both is named by its utm.\n */\nexport const TOUCH_PRIORITY = {\n /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */\n campaign: 1,\n /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */\n verified: 1,\n /** the browser said where the visitor came from; nobody chose it */\n referrer: 2,\n /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */\n claimed: 3,\n} as const satisfies Record<string, number>;\n\n/** Which reported kinds are staff facts and which are the user's claims. */\nexport const REPORTED_TOUCH_PRIORITY = {\n phone: TOUCH_PRIORITY.verified,\n manual: TOUCH_PRIORITY.verified,\n survey: TOUCH_PRIORITY.claimed,\n promo_code: TOUCH_PRIORITY.claimed,\n} as const satisfies Record<ReportedTouchKind, number>;\n"],"mappings":";;;;;;;;AASA,MAAa,iBAAiB;;AAE9B,MAAa,YAAY;;AAEzB,MAAa,iBAAiB;;AAG9B,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAKA;AACF;;AAKA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAKA,MAAa,iBAAiB;CAC5B,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,UAAU;CACV,WAAW;CACX,MAAM;CACN,SAAS;AACX;;;;;;AAOA,MAAa,oBAAoB;CAC/B,CAAC,UAAU,MAAM;CACjB,CAAC,OAAO,MAAM;CACd,CAAC,SAAS,QAAQ;CAClB,CAAC,UAAU,QAAQ;CACnB,CAAC,UAAU,QAAQ;CACnB,CAAC,cAAc,QAAQ;CACvB,CAAC,kBAAkB,QAAQ;CAC3B,CAAC,SAAS,OAAO;CACjB,CAAC,WAAW,WAAW;CACvB,CAAC,UAAU,QAAQ;CACnB,CAAC,WAAW,QAAQ;CACpB,CAAC,aAAa,UAAU;CACxB,CAAC,SAAS,UAAU;CACpB,CAAC,UAAU,GAAG;CACd,CAAC,eAAe,OAAO;CACvB,CAAC,SAAS,QAAQ;AACpB;;;;;;AAOA,MAAa,kBAAkB;;;;;;;AAU/B,MAAa,iBAAiB;CAC5B;EAAC;EAAU;EAAW,OAAO,GAAG;CAAyC;CACzE;EAAC;EAAa;EAAW,OAAO,GAAG;CAAkB;CACrD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAwC;CACvE;EAAC;EAAc;EAAW,OAAO,GAAG;CAAwB;CAC5D;EAAC;EAAS;EAAW,OAAO,GAAG;CAAmB;CAClD;EAAC;EAAU;EAAW,OAAO,GAAG;CAAyC;CACzE;EAAC;EAAU;EAAW,OAAO,GAAG;CAAoB;CACpD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAmB;CAClD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAsB;CACrD;EAAC;EAAQ;EAAU,OAAO,GAAG;CAA4D;CACzF;EAAC;EAAK;EAAU,OAAO,GAAG;CAAoC;CAC9D;EAAC;EAAY;EAAU,OAAO,GAAG;CAAiC;CAClE;EAAC;EAAU;EAAU,OAAO,GAAG;CAAoB;CACnD;EAAC;EAAU;EAAU,OAAO,GAAG;CAAoB;CACnD;EAAC;EAAa;EAAU,OAAO,GAAG;CAA4C;CAC9E;EAAC;EAAY;EAAU,OAAO,GAAG;CAAsB;CACvD;EAAC;EAAW;EAAS,OAAO,GAAG;CAAiC;AAClE;;;;;;;AAQA,MAAa,wBAAwB;CACnC,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;AACZ;;AAGA,MAAa,cAAc;AAC3B,MAAa,kBAAkB;CAAC;CAAW;CAAU;CAAc;AAAc;AACjF,MAAa,gBAAgB;CAAC;CAAS;CAAU;CAAU;AAAQ;;AAGnE,MAAa,gBAAgB,CAAC,WAAW,UAAU;;;;;;;;AAUnD,MAAa,uBAAuB;CAAC;CAAU;CAAc;CAAS;AAAQ;;;;;;;;;;;;AAc9E,MAAa,iBAAiB;;CAE5B,UAAU;;CAEV,UAAU;;CAEV,UAAU;;CAEV,SAAS;AACX;;AAGA,MAAa,0BAA0B;CACrC,OAAO,eAAe;CACtB,QAAQ,eAAe;CACvB,QAAQ,eAAe;CACvB,YAAY,eAAe;AAC7B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/attribution/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the
|
|
4
|
+
* dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with
|
|
5
|
+
* the product is its own hostnames (referrer exclusions) and its landing-page convention.
|
|
6
|
+
*/
|
|
7
|
+
/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */
|
|
8
|
+
declare const DIRECT_CHANNEL = "(direct)";
|
|
9
|
+
/** The medium of a direct session. */
|
|
10
|
+
declare const NO_MEDIUM = "(none)";
|
|
11
|
+
/** The medium of a tagged link that named a source but no medium. */
|
|
12
|
+
declare const MEDIUM_NOT_SET = "(not set)";
|
|
13
|
+
/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */
|
|
14
|
+
declare const CHANNELS: readonly ['meta', 'google', 'dv360', 'microsoft', 'tiktok', 'reddit', 'linkedin', 'snapchat', 'x', 'kakao', 'yandex', 'yahoo', 'duckduckgo', 'baidu', 'ecosia', 'naver', 'brave', 'pinterest', 'youtube',
|
|
15
|
+
/** the product's own referral programme: the session came through a member's link or code.
|
|
16
|
+
* How a product recognises one (a `/refer/<code>` path, a code at sign-up) is its own rule. Not
|
|
17
|
+
* `referral`: that word is the channel group of any outside site, and a channel of the same name
|
|
18
|
+
* would be impossible to tell apart in queries. */
|
|
19
|
+
'referral_program'];
|
|
20
|
+
type Channel = (typeof CHANNELS)[number];
|
|
21
|
+
/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
|
|
22
|
+
declare const CHANNEL_GROUPS: readonly ['direct', 'paid_search', 'paid_social', 'paid_other', 'display', 'organic_search', 'organic_social', 'organic_video', 'referral', 'email', 'affiliate', 'unassigned'];
|
|
23
|
+
type ChannelGroup = (typeof CHANNEL_GROUPS)[number];
|
|
24
|
+
/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
|
|
25
|
+
declare const SOURCE_ALIASES: {
|
|
26
|
+
readonly fb: 'meta';
|
|
27
|
+
readonly ig: 'meta';
|
|
28
|
+
readonly an: 'meta';
|
|
29
|
+
readonly msg: 'meta';
|
|
30
|
+
readonly facebook: 'meta';
|
|
31
|
+
readonly instagram: 'meta';
|
|
32
|
+
readonly bing: 'microsoft';
|
|
33
|
+
readonly twitter: 'x';
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Which click id belongs to which channel, in priority order. Every key is a field this SDK
|
|
37
|
+
* collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
|
|
38
|
+
* browser ids, present with or without a click.
|
|
39
|
+
*/
|
|
40
|
+
declare const CLICK_ID_CHANNELS: readonly [readonly ["fbclid", "meta"], readonly ["fbc", "meta"], readonly ["gclid", "google"], readonly ["gbraid", "google"], readonly ["wbraid", "google"], readonly ["gad_source", "google"], readonly ["gad_campaignid", "google"], readonly ["dclid", "dv360"], readonly ["msclkid", "microsoft"], readonly ["ttclid", "tiktok"], readonly ["rdt_cid", "reddit"], readonly ["li_fat_id", "linkedin"], readonly ["sccid", "snapchat"], readonly ["twclid", "x"], readonly ["ko_click_id", "kakao"], readonly ["yclid", "yandex"]];
|
|
41
|
+
/**
|
|
42
|
+
* A landing page reserved for one channel's ads, for ads that lost their parameters:
|
|
43
|
+
* `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
|
|
44
|
+
* that names its landing pages differently replaces this.
|
|
45
|
+
*/
|
|
46
|
+
declare const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
|
|
47
|
+
type ReferrerMedium = 'organic' | 'social' | 'video';
|
|
48
|
+
/**
|
|
49
|
+
* Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
|
|
50
|
+
* with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
|
|
51
|
+
* its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
|
|
52
|
+
* never an open tail, so `google.com.evil.io` is not Google.
|
|
53
|
+
*/
|
|
54
|
+
declare const REFERRER_SITES: readonly [readonly ["google", "organic", string], readonly ["microsoft", "organic", string], readonly ["yahoo", "organic", string], readonly ["duckduckgo", "organic", string], readonly ["baidu", "organic", string], readonly ["yandex", "organic", string], readonly ["ecosia", "organic", string], readonly ["naver", "organic", string], readonly ["brave", "organic", string], readonly ["meta", "social", string], readonly ["x", "social", string], readonly ["linkedin", "social", string], readonly ["reddit", "social", string], readonly ["tiktok", "social", string], readonly ["pinterest", "social", string], readonly ["snapchat", "social", string], readonly ["youtube", "video", string]];
|
|
55
|
+
/**
|
|
56
|
+
* Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
|
|
57
|
+
* visitor is bounced through and back from, and the local dev host. A product appends its own
|
|
58
|
+
* hostnames — a session that starts from an internal link after the session timeout refers to
|
|
59
|
+
* them. POSIX regular expressions over the lower-cased host.
|
|
60
|
+
*/
|
|
61
|
+
declare const REFERRERS_NOT_A_TOUCH: readonly [string, string, string, string, string, string];
|
|
62
|
+
/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
|
|
63
|
+
declare const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
|
|
64
|
+
declare const DISPLAY_MEDIUMS: readonly ['display', 'banner', 'expandable', 'interstitial'];
|
|
65
|
+
declare const EMAIL_MEDIUMS: readonly ['email', 'e-mail', 'e_mail', 'e mail'];
|
|
66
|
+
/** Where a touch came from: a tracked session, or a report by the user or staff. */
|
|
67
|
+
declare const TOUCH_SOURCES: readonly ['tracked', 'reported'];
|
|
68
|
+
type TouchSource = (typeof TOUCH_SOURCES)[number];
|
|
69
|
+
/**
|
|
70
|
+
* How a reported touch was learned:
|
|
71
|
+
* - survey: the user answered "how did you hear about us" (onboarding, checkout)
|
|
72
|
+
* - promo_code: the user redeemed a code that belongs to a channel
|
|
73
|
+
* - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
|
|
74
|
+
* - manual: staff recorded what a customer told them
|
|
75
|
+
*/
|
|
76
|
+
declare const REPORTED_TOUCH_KINDS: readonly ['survey', 'promo_code', 'phone', 'manual'];
|
|
77
|
+
type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];
|
|
78
|
+
/**
|
|
79
|
+
* How much a touch is worth against another when attribution has to choose between sessions;
|
|
80
|
+
* lower wins, and the latest wins among equals. Derived in the views, never stored, so
|
|
81
|
+
* renumbering is a view regeneration.
|
|
82
|
+
*
|
|
83
|
+
* This ranks touches against each other. Within one session the rules that name its channel have
|
|
84
|
+
* their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
|
|
85
|
+
* and the first that says something wins; the session's priority is then the tier of that rule.
|
|
86
|
+
* So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
|
|
87
|
+
* later one is credited, while one session carrying both is named by its utm.
|
|
88
|
+
*/
|
|
89
|
+
declare const TOUCH_PRIORITY: {
|
|
90
|
+
/** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
|
|
91
|
+
readonly campaign: 1;
|
|
92
|
+
/** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
|
|
93
|
+
readonly verified: 1;
|
|
94
|
+
/** the browser said where the visitor came from; nobody chose it */
|
|
95
|
+
readonly referrer: 2;
|
|
96
|
+
/** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
|
|
97
|
+
readonly claimed: 3;
|
|
98
|
+
};
|
|
99
|
+
/** Which reported kinds are staff facts and which are the user's claims. */
|
|
100
|
+
declare const REPORTED_TOUCH_PRIORITY: {
|
|
101
|
+
readonly phone: 1;
|
|
102
|
+
readonly manual: 1;
|
|
103
|
+
readonly survey: 3;
|
|
104
|
+
readonly promo_code: 3;
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { AD_LANDING_PAGE, CHANNELS, CHANNEL_GROUPS, CLICK_ID_CHANNELS, Channel, ChannelGroup, DIRECT_CHANNEL, DISPLAY_MEDIUMS, EMAIL_MEDIUMS, MEDIUM_NOT_SET, NO_MEDIUM, PAID_MEDIUM, REFERRERS_NOT_A_TOUCH, REFERRER_SITES, REPORTED_TOUCH_KINDS, REPORTED_TOUCH_PRIORITY, ReferrerMedium, ReportedTouchKind, SOURCE_ALIASES, TOUCH_PRIORITY, TOUCH_SOURCES, TouchSource };
|
|
108
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/attribution/index.ts"],"mappings":";;;;;;;cASa;;cAEA;;cAEA;;cAGA;;;;;;KA2BD,kBAAkB;;cAGjB;KAeD,uBAAuB;;cAGtB;WACP;WACA;WACA;WACC;WACK;WACC;WACL;WACG;;;;;;;cAQE;;;;;;cAwBA;KAED;;;;;;;cAQC;;;;;;;cA0BA;;cAUA;cACA;cACA;;cAGA;KACD,sBAAsB;;;;;;;;cASrB;KACD,4BAA4B;;;;;;;;;;;;cAa3B;;WAED;;WAEA;;WAEA;;WAED;;;cAIE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/attribution/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the
|
|
4
|
+
* dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with
|
|
5
|
+
* the product is its own hostnames (referrer exclusions) and its landing-page convention.
|
|
6
|
+
*/
|
|
7
|
+
/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */
|
|
8
|
+
declare const DIRECT_CHANNEL = "(direct)";
|
|
9
|
+
/** The medium of a direct session. */
|
|
10
|
+
declare const NO_MEDIUM = "(none)";
|
|
11
|
+
/** The medium of a tagged link that named a source but no medium. */
|
|
12
|
+
declare const MEDIUM_NOT_SET = "(not set)";
|
|
13
|
+
/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */
|
|
14
|
+
declare const CHANNELS: readonly ['meta', 'google', 'dv360', 'microsoft', 'tiktok', 'reddit', 'linkedin', 'snapchat', 'x', 'kakao', 'yandex', 'yahoo', 'duckduckgo', 'baidu', 'ecosia', 'naver', 'brave', 'pinterest', 'youtube',
|
|
15
|
+
/** the product's own referral programme: the session came through a member's link or code.
|
|
16
|
+
* How a product recognises one (a `/refer/<code>` path, a code at sign-up) is its own rule. Not
|
|
17
|
+
* `referral`: that word is the channel group of any outside site, and a channel of the same name
|
|
18
|
+
* would be impossible to tell apart in queries. */
|
|
19
|
+
'referral_program'];
|
|
20
|
+
type Channel = (typeof CHANNELS)[number];
|
|
21
|
+
/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
|
|
22
|
+
declare const CHANNEL_GROUPS: readonly ['direct', 'paid_search', 'paid_social', 'paid_other', 'display', 'organic_search', 'organic_social', 'organic_video', 'referral', 'email', 'affiliate', 'unassigned'];
|
|
23
|
+
type ChannelGroup = (typeof CHANNEL_GROUPS)[number];
|
|
24
|
+
/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
|
|
25
|
+
declare const SOURCE_ALIASES: {
|
|
26
|
+
readonly fb: 'meta';
|
|
27
|
+
readonly ig: 'meta';
|
|
28
|
+
readonly an: 'meta';
|
|
29
|
+
readonly msg: 'meta';
|
|
30
|
+
readonly facebook: 'meta';
|
|
31
|
+
readonly instagram: 'meta';
|
|
32
|
+
readonly bing: 'microsoft';
|
|
33
|
+
readonly twitter: 'x';
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Which click id belongs to which channel, in priority order. Every key is a field this SDK
|
|
37
|
+
* collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
|
|
38
|
+
* browser ids, present with or without a click.
|
|
39
|
+
*/
|
|
40
|
+
declare const CLICK_ID_CHANNELS: readonly [readonly ["fbclid", "meta"], readonly ["fbc", "meta"], readonly ["gclid", "google"], readonly ["gbraid", "google"], readonly ["wbraid", "google"], readonly ["gad_source", "google"], readonly ["gad_campaignid", "google"], readonly ["dclid", "dv360"], readonly ["msclkid", "microsoft"], readonly ["ttclid", "tiktok"], readonly ["rdt_cid", "reddit"], readonly ["li_fat_id", "linkedin"], readonly ["sccid", "snapchat"], readonly ["twclid", "x"], readonly ["ko_click_id", "kakao"], readonly ["yclid", "yandex"]];
|
|
41
|
+
/**
|
|
42
|
+
* A landing page reserved for one channel's ads, for ads that lost their parameters:
|
|
43
|
+
* `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
|
|
44
|
+
* that names its landing pages differently replaces this.
|
|
45
|
+
*/
|
|
46
|
+
declare const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
|
|
47
|
+
type ReferrerMedium = 'organic' | 'social' | 'video';
|
|
48
|
+
/**
|
|
49
|
+
* Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
|
|
50
|
+
* with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
|
|
51
|
+
* its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
|
|
52
|
+
* never an open tail, so `google.com.evil.io` is not Google.
|
|
53
|
+
*/
|
|
54
|
+
declare const REFERRER_SITES: readonly [readonly ["google", "organic", string], readonly ["microsoft", "organic", string], readonly ["yahoo", "organic", string], readonly ["duckduckgo", "organic", string], readonly ["baidu", "organic", string], readonly ["yandex", "organic", string], readonly ["ecosia", "organic", string], readonly ["naver", "organic", string], readonly ["brave", "organic", string], readonly ["meta", "social", string], readonly ["x", "social", string], readonly ["linkedin", "social", string], readonly ["reddit", "social", string], readonly ["tiktok", "social", string], readonly ["pinterest", "social", string], readonly ["snapchat", "social", string], readonly ["youtube", "video", string]];
|
|
55
|
+
/**
|
|
56
|
+
* Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
|
|
57
|
+
* visitor is bounced through and back from, and the local dev host. A product appends its own
|
|
58
|
+
* hostnames — a session that starts from an internal link after the session timeout refers to
|
|
59
|
+
* them. POSIX regular expressions over the lower-cased host.
|
|
60
|
+
*/
|
|
61
|
+
declare const REFERRERS_NOT_A_TOUCH: readonly [string, string, string, string, string, string];
|
|
62
|
+
/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
|
|
63
|
+
declare const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
|
|
64
|
+
declare const DISPLAY_MEDIUMS: readonly ['display', 'banner', 'expandable', 'interstitial'];
|
|
65
|
+
declare const EMAIL_MEDIUMS: readonly ['email', 'e-mail', 'e_mail', 'e mail'];
|
|
66
|
+
/** Where a touch came from: a tracked session, or a report by the user or staff. */
|
|
67
|
+
declare const TOUCH_SOURCES: readonly ['tracked', 'reported'];
|
|
68
|
+
type TouchSource = (typeof TOUCH_SOURCES)[number];
|
|
69
|
+
/**
|
|
70
|
+
* How a reported touch was learned:
|
|
71
|
+
* - survey: the user answered "how did you hear about us" (onboarding, checkout)
|
|
72
|
+
* - promo_code: the user redeemed a code that belongs to a channel
|
|
73
|
+
* - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
|
|
74
|
+
* - manual: staff recorded what a customer told them
|
|
75
|
+
*/
|
|
76
|
+
declare const REPORTED_TOUCH_KINDS: readonly ['survey', 'promo_code', 'phone', 'manual'];
|
|
77
|
+
type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];
|
|
78
|
+
/**
|
|
79
|
+
* How much a touch is worth against another when attribution has to choose between sessions;
|
|
80
|
+
* lower wins, and the latest wins among equals. Derived in the views, never stored, so
|
|
81
|
+
* renumbering is a view regeneration.
|
|
82
|
+
*
|
|
83
|
+
* This ranks touches against each other. Within one session the rules that name its channel have
|
|
84
|
+
* their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
|
|
85
|
+
* and the first that says something wins; the session's priority is then the tier of that rule.
|
|
86
|
+
* So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
|
|
87
|
+
* later one is credited, while one session carrying both is named by its utm.
|
|
88
|
+
*/
|
|
89
|
+
declare const TOUCH_PRIORITY: {
|
|
90
|
+
/** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
|
|
91
|
+
readonly campaign: 1;
|
|
92
|
+
/** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
|
|
93
|
+
readonly verified: 1;
|
|
94
|
+
/** the browser said where the visitor came from; nobody chose it */
|
|
95
|
+
readonly referrer: 2;
|
|
96
|
+
/** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
|
|
97
|
+
readonly claimed: 3;
|
|
98
|
+
};
|
|
99
|
+
/** Which reported kinds are staff facts and which are the user's claims. */
|
|
100
|
+
declare const REPORTED_TOUCH_PRIORITY: {
|
|
101
|
+
readonly phone: 1;
|
|
102
|
+
readonly manual: 1;
|
|
103
|
+
readonly survey: 3;
|
|
104
|
+
readonly promo_code: 3;
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { AD_LANDING_PAGE, CHANNELS, CHANNEL_GROUPS, CLICK_ID_CHANNELS, Channel, ChannelGroup, DIRECT_CHANNEL, DISPLAY_MEDIUMS, EMAIL_MEDIUMS, MEDIUM_NOT_SET, NO_MEDIUM, PAID_MEDIUM, REFERRERS_NOT_A_TOUCH, REFERRER_SITES, REPORTED_TOUCH_KINDS, REPORTED_TOUCH_PRIORITY, ReferrerMedium, ReportedTouchKind, SOURCE_ALIASES, TOUCH_PRIORITY, TOUCH_SOURCES, TouchSource };
|
|
108
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/attribution/index.ts"],"mappings":";;;;;;;cASa;;cAEA;;cAEA;;cAGA;;;;;;KA2BD,kBAAkB;;cAGjB;KAeD,uBAAuB;;cAGtB;WACP;WACA;WACA;WACC;WACK;WACC;WACL;WACG;;;;;;;cAQE;;;;;;cAwBA;KAED;;;;;;;cAQC;;;;;;;cA0BA;;cAUA;cACA;cACA;;cAGA;KACD,sBAAsB;;;;;;;;cASrB;KACD,4BAA4B;;;;;;;;;;;;cAa3B;;WAED;;WAEA;;WAEA;;WAED;;;cAIE"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
//#region src/attribution/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the
|
|
4
|
+
* dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with
|
|
5
|
+
* the product is its own hostnames (referrer exclusions) and its landing-page convention.
|
|
6
|
+
*/
|
|
7
|
+
/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */
|
|
8
|
+
const DIRECT_CHANNEL = "(direct)";
|
|
9
|
+
/** The medium of a direct session. */
|
|
10
|
+
const NO_MEDIUM = "(none)";
|
|
11
|
+
/** The medium of a tagged link that named a source but no medium. */
|
|
12
|
+
const MEDIUM_NOT_SET = "(not set)";
|
|
13
|
+
/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */
|
|
14
|
+
const CHANNELS = [
|
|
15
|
+
"meta",
|
|
16
|
+
"google",
|
|
17
|
+
"dv360",
|
|
18
|
+
"microsoft",
|
|
19
|
+
"tiktok",
|
|
20
|
+
"reddit",
|
|
21
|
+
"linkedin",
|
|
22
|
+
"snapchat",
|
|
23
|
+
"x",
|
|
24
|
+
"kakao",
|
|
25
|
+
"yandex",
|
|
26
|
+
"yahoo",
|
|
27
|
+
"duckduckgo",
|
|
28
|
+
"baidu",
|
|
29
|
+
"ecosia",
|
|
30
|
+
"naver",
|
|
31
|
+
"brave",
|
|
32
|
+
"pinterest",
|
|
33
|
+
"youtube",
|
|
34
|
+
"referral_program"
|
|
35
|
+
];
|
|
36
|
+
/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
|
|
37
|
+
const CHANNEL_GROUPS = [
|
|
38
|
+
"direct",
|
|
39
|
+
"paid_search",
|
|
40
|
+
"paid_social",
|
|
41
|
+
"paid_other",
|
|
42
|
+
"display",
|
|
43
|
+
"organic_search",
|
|
44
|
+
"organic_social",
|
|
45
|
+
"organic_video",
|
|
46
|
+
"referral",
|
|
47
|
+
"email",
|
|
48
|
+
"affiliate",
|
|
49
|
+
"unassigned"
|
|
50
|
+
];
|
|
51
|
+
/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
|
|
52
|
+
const SOURCE_ALIASES = {
|
|
53
|
+
fb: "meta",
|
|
54
|
+
ig: "meta",
|
|
55
|
+
an: "meta",
|
|
56
|
+
msg: "meta",
|
|
57
|
+
facebook: "meta",
|
|
58
|
+
instagram: "meta",
|
|
59
|
+
bing: "microsoft",
|
|
60
|
+
twitter: "x"
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Which click id belongs to which channel, in priority order. Every key is a field this SDK
|
|
64
|
+
* collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
|
|
65
|
+
* browser ids, present with or without a click.
|
|
66
|
+
*/
|
|
67
|
+
const CLICK_ID_CHANNELS = [
|
|
68
|
+
["fbclid", "meta"],
|
|
69
|
+
["fbc", "meta"],
|
|
70
|
+
["gclid", "google"],
|
|
71
|
+
["gbraid", "google"],
|
|
72
|
+
["wbraid", "google"],
|
|
73
|
+
["gad_source", "google"],
|
|
74
|
+
["gad_campaignid", "google"],
|
|
75
|
+
["dclid", "dv360"],
|
|
76
|
+
["msclkid", "microsoft"],
|
|
77
|
+
["ttclid", "tiktok"],
|
|
78
|
+
["rdt_cid", "reddit"],
|
|
79
|
+
["li_fat_id", "linkedin"],
|
|
80
|
+
["sccid", "snapchat"],
|
|
81
|
+
["twclid", "x"],
|
|
82
|
+
["ko_click_id", "kakao"],
|
|
83
|
+
["yclid", "yandex"]
|
|
84
|
+
];
|
|
85
|
+
/**
|
|
86
|
+
* A landing page reserved for one channel's ads, for ads that lost their parameters:
|
|
87
|
+
* `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
|
|
88
|
+
* that names its landing pages differently replaces this.
|
|
89
|
+
*/
|
|
90
|
+
const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
|
|
91
|
+
/**
|
|
92
|
+
* Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
|
|
93
|
+
* with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
|
|
94
|
+
* its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
|
|
95
|
+
* never an open tail, so `google.com.evil.io` is not Google.
|
|
96
|
+
*/
|
|
97
|
+
const REFERRER_SITES = [
|
|
98
|
+
[
|
|
99
|
+
"google",
|
|
100
|
+
"organic",
|
|
101
|
+
String.raw`(^|\.)google\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"microsoft",
|
|
105
|
+
"organic",
|
|
106
|
+
String.raw`(^|\.)bing\.com$`
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"yahoo",
|
|
110
|
+
"organic",
|
|
111
|
+
String.raw`(^|\.)yahoo\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"duckduckgo",
|
|
115
|
+
"organic",
|
|
116
|
+
String.raw`(^|\.)duckduckgo\.com$`
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
"baidu",
|
|
120
|
+
"organic",
|
|
121
|
+
String.raw`(^|\.)baidu\.com$`
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
"yandex",
|
|
125
|
+
"organic",
|
|
126
|
+
String.raw`(^|\.)yandex\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
"ecosia",
|
|
130
|
+
"organic",
|
|
131
|
+
String.raw`(^|\.)ecosia\.org$`
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"naver",
|
|
135
|
+
"organic",
|
|
136
|
+
String.raw`(^|\.)naver\.com$`
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
"brave",
|
|
140
|
+
"organic",
|
|
141
|
+
String.raw`^search\.brave\.com$`
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
"meta",
|
|
145
|
+
"social",
|
|
146
|
+
String.raw`(^|\.)(facebook\.com|instagram\.com|fb\.com|threads\.net)$`
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
"x",
|
|
150
|
+
"social",
|
|
151
|
+
String.raw`(^|\.)(twitter\.com|x\.com|t\.co)$`
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
"linkedin",
|
|
155
|
+
"social",
|
|
156
|
+
String.raw`(^|\.)(linkedin\.com|lnkd\.in)$`
|
|
157
|
+
],
|
|
158
|
+
[
|
|
159
|
+
"reddit",
|
|
160
|
+
"social",
|
|
161
|
+
String.raw`(^|\.)reddit\.com$`
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
"tiktok",
|
|
165
|
+
"social",
|
|
166
|
+
String.raw`(^|\.)tiktok\.com$`
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
"pinterest",
|
|
170
|
+
"social",
|
|
171
|
+
String.raw`(^|\.)pinterest\.[a-z]{2,}(\.[a-z]{2,3})?$`
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"snapchat",
|
|
175
|
+
"social",
|
|
176
|
+
String.raw`(^|\.)snapchat\.com$`
|
|
177
|
+
],
|
|
178
|
+
[
|
|
179
|
+
"youtube",
|
|
180
|
+
"video",
|
|
181
|
+
String.raw`(^|\.)(youtube\.com|youtu\.be)$`
|
|
182
|
+
]
|
|
183
|
+
];
|
|
184
|
+
/**
|
|
185
|
+
* Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
|
|
186
|
+
* visitor is bounced through and back from, and the local dev host. A product appends its own
|
|
187
|
+
* hostnames — a session that starts from an internal link after the session timeout refers to
|
|
188
|
+
* them. POSIX regular expressions over the lower-cased host.
|
|
189
|
+
*/
|
|
190
|
+
const REFERRERS_NOT_A_TOUCH = [
|
|
191
|
+
String.raw`^localhost(:|$)`,
|
|
192
|
+
String.raw`(^|\.)stripe\.com$`,
|
|
193
|
+
String.raw`^(pay|accounts)\.google\.com$`,
|
|
194
|
+
String.raw`^(appleid|apps)\.apple\.com$`,
|
|
195
|
+
String.raw`^play\.google\.com$`,
|
|
196
|
+
String.raw`^login\.microsoftonline\.com$`
|
|
197
|
+
];
|
|
198
|
+
/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
|
|
199
|
+
const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
|
|
200
|
+
const DISPLAY_MEDIUMS = [
|
|
201
|
+
"display",
|
|
202
|
+
"banner",
|
|
203
|
+
"expandable",
|
|
204
|
+
"interstitial"
|
|
205
|
+
];
|
|
206
|
+
const EMAIL_MEDIUMS = [
|
|
207
|
+
"email",
|
|
208
|
+
"e-mail",
|
|
209
|
+
"e_mail",
|
|
210
|
+
"e mail"
|
|
211
|
+
];
|
|
212
|
+
/** Where a touch came from: a tracked session, or a report by the user or staff. */
|
|
213
|
+
const TOUCH_SOURCES = ["tracked", "reported"];
|
|
214
|
+
/**
|
|
215
|
+
* How a reported touch was learned:
|
|
216
|
+
* - survey: the user answered "how did you hear about us" (onboarding, checkout)
|
|
217
|
+
* - promo_code: the user redeemed a code that belongs to a channel
|
|
218
|
+
* - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
|
|
219
|
+
* - manual: staff recorded what a customer told them
|
|
220
|
+
*/
|
|
221
|
+
const REPORTED_TOUCH_KINDS = [
|
|
222
|
+
"survey",
|
|
223
|
+
"promo_code",
|
|
224
|
+
"phone",
|
|
225
|
+
"manual"
|
|
226
|
+
];
|
|
227
|
+
/**
|
|
228
|
+
* How much a touch is worth against another when attribution has to choose between sessions;
|
|
229
|
+
* lower wins, and the latest wins among equals. Derived in the views, never stored, so
|
|
230
|
+
* renumbering is a view regeneration.
|
|
231
|
+
*
|
|
232
|
+
* This ranks touches against each other. Within one session the rules that name its channel have
|
|
233
|
+
* their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
|
|
234
|
+
* and the first that says something wins; the session's priority is then the tier of that rule.
|
|
235
|
+
* So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
|
|
236
|
+
* later one is credited, while one session carrying both is named by its utm.
|
|
237
|
+
*/
|
|
238
|
+
const TOUCH_PRIORITY = {
|
|
239
|
+
/** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
|
|
240
|
+
campaign: 1,
|
|
241
|
+
/** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
|
|
242
|
+
verified: 1,
|
|
243
|
+
/** the browser said where the visitor came from; nobody chose it */
|
|
244
|
+
referrer: 2,
|
|
245
|
+
/** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
|
|
246
|
+
claimed: 3
|
|
247
|
+
};
|
|
248
|
+
/** Which reported kinds are staff facts and which are the user's claims. */
|
|
249
|
+
const REPORTED_TOUCH_PRIORITY = {
|
|
250
|
+
phone: TOUCH_PRIORITY.verified,
|
|
251
|
+
manual: TOUCH_PRIORITY.verified,
|
|
252
|
+
survey: TOUCH_PRIORITY.claimed,
|
|
253
|
+
promo_code: TOUCH_PRIORITY.claimed
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
export { AD_LANDING_PAGE, CHANNELS, CHANNEL_GROUPS, CLICK_ID_CHANNELS, DIRECT_CHANNEL, DISPLAY_MEDIUMS, EMAIL_MEDIUMS, MEDIUM_NOT_SET, NO_MEDIUM, PAID_MEDIUM, REFERRERS_NOT_A_TOUCH, REFERRER_SITES, REPORTED_TOUCH_KINDS, REPORTED_TOUCH_PRIORITY, SOURCE_ALIASES, TOUCH_PRIORITY, TOUCH_SOURCES };
|
|
257
|
+
|
|
258
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/attribution/index.ts"],"sourcesContent":["import type { AdvertisingInfo } from '../track/types';\n\n/**\n * The vocabulary attribution is built from, shared by every product's `touchpoint` view and by the\n * dashboards that read it. Data only, no SQL: a product turns these into its view. What stays with\n * the product is its own hostnames (referrer exclusions) and its landing-page convention.\n */\n\n/** A session that arrived through nothing we can name. GA's spelling, so dashboards read as GA. */\nexport const DIRECT_CHANNEL = '(direct)';\n/** The medium of a direct session. */\nexport const NO_MEDIUM = '(none)';\n/** The medium of a tagged link that named a source but no medium. */\nexport const MEDIUM_NOT_SET = '(not set)';\n\n/** The channels the rules below can name. A `utm_source` outside this list is its own channel. */\nexport const CHANNELS = [\n 'meta',\n 'google',\n 'dv360',\n 'microsoft',\n 'tiktok',\n 'reddit',\n 'linkedin',\n 'snapchat',\n 'x',\n 'kakao',\n 'yandex',\n 'yahoo',\n 'duckduckgo',\n 'baidu',\n 'ecosia',\n 'naver',\n 'brave',\n 'pinterest',\n 'youtube',\n /** the product's own referral programme: the session came through a member's link or code.\n * How a product recognises one (a `/refer/<code>` path, a code at sign-up) is its own rule. Not\n * `referral`: that word is the channel group of any outside site, and a channel of the same name\n * would be impossible to tell apart in queries. */\n 'referral_program',\n] as const;\n\nexport type Channel = (typeof CHANNELS)[number];\n\n/** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */\nexport const CHANNEL_GROUPS = [\n 'direct',\n 'paid_search',\n 'paid_social',\n 'paid_other',\n 'display',\n 'organic_search',\n 'organic_social',\n 'organic_video',\n 'referral',\n 'email',\n 'affiliate',\n 'unassigned',\n] as const;\n\nexport type ChannelGroup = (typeof CHANNEL_GROUPS)[number];\n\n/** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */\nexport const SOURCE_ALIASES = {\n fb: 'meta',\n ig: 'meta',\n an: 'meta',\n msg: 'meta',\n facebook: 'meta',\n instagram: 'meta',\n bing: 'microsoft',\n twitter: 'x',\n} as const satisfies Record<string, Channel>;\n\n/**\n * Which click id belongs to which channel, in priority order. Every key is a field this SDK\n * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel\n * browser ids, present with or without a click.\n */\nexport const CLICK_ID_CHANNELS = [\n ['fbclid', 'meta'],\n ['fbc', 'meta'],\n ['gclid', 'google'],\n ['gbraid', 'google'],\n ['wbraid', 'google'],\n ['gad_source', 'google'],\n ['gad_campaignid', 'google'],\n ['dclid', 'dv360'],\n ['msclkid', 'microsoft'],\n ['ttclid', 'tiktok'],\n ['rdt_cid', 'reddit'],\n ['li_fat_id', 'linkedin'],\n ['sccid', 'snapchat'],\n ['twclid', 'x'],\n ['ko_click_id', 'kakao'],\n ['yclid', 'yandex'],\n] as const satisfies readonly (readonly [keyof AdvertisingInfo, Channel])[];\n\n/**\n * A landing page reserved for one channel's ads, for ads that lost their parameters:\n * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product\n * that names its landing pages differently replaces this.\n */\nexport const AD_LANDING_PAGE = '^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)';\n\nexport type ReferrerMedium = 'organic' | 'social' | 'video';\n\n/**\n * Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,\n * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as\n * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),\n * never an open tail, so `google.com.evil.io` is not Google.\n */\nexport const REFERRER_SITES = [\n ['google', 'organic', String.raw`(^|\\.)google\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['microsoft', 'organic', String.raw`(^|\\.)bing\\.com$`],\n ['yahoo', 'organic', String.raw`(^|\\.)yahoo\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['duckduckgo', 'organic', String.raw`(^|\\.)duckduckgo\\.com$`],\n ['baidu', 'organic', String.raw`(^|\\.)baidu\\.com$`],\n ['yandex', 'organic', String.raw`(^|\\.)yandex\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['ecosia', 'organic', String.raw`(^|\\.)ecosia\\.org$`],\n ['naver', 'organic', String.raw`(^|\\.)naver\\.com$`],\n ['brave', 'organic', String.raw`^search\\.brave\\.com$`],\n ['meta', 'social', String.raw`(^|\\.)(facebook\\.com|instagram\\.com|fb\\.com|threads\\.net)$`],\n ['x', 'social', String.raw`(^|\\.)(twitter\\.com|x\\.com|t\\.co)$`],\n ['linkedin', 'social', String.raw`(^|\\.)(linkedin\\.com|lnkd\\.in)$`],\n ['reddit', 'social', String.raw`(^|\\.)reddit\\.com$`],\n ['tiktok', 'social', String.raw`(^|\\.)tiktok\\.com$`],\n ['pinterest', 'social', String.raw`(^|\\.)pinterest\\.[a-z]{2,}(\\.[a-z]{2,3})?$`],\n ['snapchat', 'social', String.raw`(^|\\.)snapchat\\.com$`],\n ['youtube', 'video', String.raw`(^|\\.)(youtube\\.com|youtu\\.be)$`],\n] as const satisfies readonly (readonly [Channel, ReferrerMedium, string])[];\n\n/**\n * Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a\n * visitor is bounced through and back from, and the local dev host. A product appends its own\n * hostnames — a session that starts from an internal link after the session timeout refers to\n * them. POSIX regular expressions over the lower-cased host.\n */\nexport const REFERRERS_NOT_A_TOUCH = [\n String.raw`^localhost(:|$)`,\n String.raw`(^|\\.)stripe\\.com$`,\n String.raw`^(pay|accounts)\\.google\\.com$`,\n String.raw`^(appleid|apps)\\.apple\\.com$`,\n String.raw`^play\\.google\\.com$`,\n String.raw`^login\\.microsoftonline\\.com$`,\n] as const;\n\n/** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */\nexport const PAID_MEDIUM = '^(.*cp.*|ppc|retargeting|paid.*)$';\nexport const DISPLAY_MEDIUMS = ['display', 'banner', 'expandable', 'interstitial'] as const;\nexport const EMAIL_MEDIUMS = ['email', 'e-mail', 'e_mail', 'e mail'] as const;\n\n/** Where a touch came from: a tracked session, or a report by the user or staff. */\nexport const TOUCH_SOURCES = ['tracked', 'reported'] as const;\nexport type TouchSource = (typeof TOUCH_SOURCES)[number];\n\n/**\n * How a reported touch was learned:\n * - survey: the user answered \"how did you hear about us\" (onboarding, checkout)\n * - promo_code: the user redeemed a code that belongs to a channel\n * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system\n * - manual: staff recorded what a customer told them\n */\nexport const REPORTED_TOUCH_KINDS = ['survey', 'promo_code', 'phone', 'manual'] as const;\nexport type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];\n\n/**\n * How much a touch is worth against another when attribution has to choose between sessions;\n * lower wins, and the latest wins among equals. Derived in the views, never stored, so\n * renumbering is a view regeneration.\n *\n * This ranks touches against each other. Within one session the rules that name its channel have\n * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —\n * and the first that says something wins; the session's priority is then the tier of that rule.\n * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the\n * later one is credited, while one session carrying both is named by its utm.\n */\nexport const TOUCH_PRIORITY = {\n /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */\n campaign: 1,\n /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */\n verified: 1,\n /** the browser said where the visitor came from; nobody chose it */\n referrer: 2,\n /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */\n claimed: 3,\n} as const satisfies Record<string, number>;\n\n/** Which reported kinds are staff facts and which are the user's claims. */\nexport const REPORTED_TOUCH_PRIORITY = {\n phone: TOUCH_PRIORITY.verified,\n manual: TOUCH_PRIORITY.verified,\n survey: TOUCH_PRIORITY.claimed,\n promo_code: TOUCH_PRIORITY.claimed,\n} as const satisfies Record<ReportedTouchKind, number>;\n"],"mappings":";;;;;;;AASA,MAAa,iBAAiB;;AAE9B,MAAa,YAAY;;AAEzB,MAAa,iBAAiB;;AAG9B,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAKA;AACF;;AAKA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAKA,MAAa,iBAAiB;CAC5B,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,UAAU;CACV,WAAW;CACX,MAAM;CACN,SAAS;AACX;;;;;;AAOA,MAAa,oBAAoB;CAC/B,CAAC,UAAU,MAAM;CACjB,CAAC,OAAO,MAAM;CACd,CAAC,SAAS,QAAQ;CAClB,CAAC,UAAU,QAAQ;CACnB,CAAC,UAAU,QAAQ;CACnB,CAAC,cAAc,QAAQ;CACvB,CAAC,kBAAkB,QAAQ;CAC3B,CAAC,SAAS,OAAO;CACjB,CAAC,WAAW,WAAW;CACvB,CAAC,UAAU,QAAQ;CACnB,CAAC,WAAW,QAAQ;CACpB,CAAC,aAAa,UAAU;CACxB,CAAC,SAAS,UAAU;CACpB,CAAC,UAAU,GAAG;CACd,CAAC,eAAe,OAAO;CACvB,CAAC,SAAS,QAAQ;AACpB;;;;;;AAOA,MAAa,kBAAkB;;;;;;;AAU/B,MAAa,iBAAiB;CAC5B;EAAC;EAAU;EAAW,OAAO,GAAG;CAAyC;CACzE;EAAC;EAAa;EAAW,OAAO,GAAG;CAAkB;CACrD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAwC;CACvE;EAAC;EAAc;EAAW,OAAO,GAAG;CAAwB;CAC5D;EAAC;EAAS;EAAW,OAAO,GAAG;CAAmB;CAClD;EAAC;EAAU;EAAW,OAAO,GAAG;CAAyC;CACzE;EAAC;EAAU;EAAW,OAAO,GAAG;CAAoB;CACpD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAmB;CAClD;EAAC;EAAS;EAAW,OAAO,GAAG;CAAsB;CACrD;EAAC;EAAQ;EAAU,OAAO,GAAG;CAA4D;CACzF;EAAC;EAAK;EAAU,OAAO,GAAG;CAAoC;CAC9D;EAAC;EAAY;EAAU,OAAO,GAAG;CAAiC;CAClE;EAAC;EAAU;EAAU,OAAO,GAAG;CAAoB;CACnD;EAAC;EAAU;EAAU,OAAO,GAAG;CAAoB;CACnD;EAAC;EAAa;EAAU,OAAO,GAAG;CAA4C;CAC9E;EAAC;EAAY;EAAU,OAAO,GAAG;CAAsB;CACvD;EAAC;EAAW;EAAS,OAAO,GAAG;CAAiC;AAClE;;;;;;;AAQA,MAAa,wBAAwB;CACnC,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;CACV,OAAO,GAAG;AACZ;;AAGA,MAAa,cAAc;AAC3B,MAAa,kBAAkB;CAAC;CAAW;CAAU;CAAc;AAAc;AACjF,MAAa,gBAAgB;CAAC;CAAS;CAAU;CAAU;AAAQ;;AAGnE,MAAa,gBAAgB,CAAC,WAAW,UAAU;;;;;;;;AAUnD,MAAa,uBAAuB;CAAC;CAAU;CAAc;CAAS;AAAQ;;;;;;;;;;;;AAc9E,MAAa,iBAAiB;;CAE5B,UAAU;;CAEV,UAAU;;CAEV,UAAU;;CAEV,SAAS;AACX;;AAGA,MAAa,0BAA0B;CACrC,OAAO,eAAe;CACtB,QAAQ,eAAe;CACvB,QAAQ,eAAe;CACvB,YAAY,eAAe;AAC7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/analytics",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
"default": "./dist/index.cjs"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
+
"./attribution": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/attribution/index.d.mts",
|
|
27
|
+
"default": "./dist/attribution/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/attribution/index.d.cts",
|
|
31
|
+
"default": "./dist/attribution/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
24
34
|
"./native": {
|
|
25
35
|
"import": {
|
|
26
36
|
"types": "./dist/native/index.d.mts",
|