@shware/analytics 8.9.0 → 8.10.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.
@@ -0,0 +1,274 @@
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
+ ];
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
+ exports.AD_LANDING_PAGE = AD_LANDING_PAGE;
257
+ exports.CHANNELS = CHANNELS;
258
+ exports.CHANNEL_GROUPS = CHANNEL_GROUPS;
259
+ exports.CLICK_ID_CHANNELS = CLICK_ID_CHANNELS;
260
+ exports.DIRECT_CHANNEL = DIRECT_CHANNEL;
261
+ exports.DISPLAY_MEDIUMS = DISPLAY_MEDIUMS;
262
+ exports.EMAIL_MEDIUMS = EMAIL_MEDIUMS;
263
+ exports.MEDIUM_NOT_SET = MEDIUM_NOT_SET;
264
+ exports.NO_MEDIUM = NO_MEDIUM;
265
+ exports.PAID_MEDIUM = PAID_MEDIUM;
266
+ exports.REFERRERS_NOT_A_TOUCH = REFERRERS_NOT_A_TOUCH;
267
+ exports.REFERRER_SITES = REFERRER_SITES;
268
+ exports.REPORTED_TOUCH_KINDS = REPORTED_TOUCH_KINDS;
269
+ exports.REPORTED_TOUCH_PRIORITY = REPORTED_TOUCH_PRIORITY;
270
+ exports.SOURCE_ALIASES = SOURCE_ALIASES;
271
+ exports.TOUCH_PRIORITY = TOUCH_PRIORITY;
272
+ exports.TOUCH_SOURCES = TOUCH_SOURCES;
273
+
274
+ //# 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] 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;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,103 @@
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
+ type Channel = (typeof CHANNELS)[number];
16
+ /** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
17
+ declare const CHANNEL_GROUPS: readonly ['direct', 'paid_search', 'paid_social', 'paid_other', 'display', 'organic_search', 'organic_social', 'organic_video', 'referral', 'email', 'affiliate', 'unassigned'];
18
+ type ChannelGroup = (typeof CHANNEL_GROUPS)[number];
19
+ /** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
20
+ declare const SOURCE_ALIASES: {
21
+ readonly fb: 'meta';
22
+ readonly ig: 'meta';
23
+ readonly an: 'meta';
24
+ readonly msg: 'meta';
25
+ readonly facebook: 'meta';
26
+ readonly instagram: 'meta';
27
+ readonly bing: 'microsoft';
28
+ readonly twitter: 'x';
29
+ };
30
+ /**
31
+ * Which click id belongs to which channel, in priority order. Every key is a field this SDK
32
+ * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
33
+ * browser ids, present with or without a click.
34
+ */
35
+ 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"]];
36
+ /**
37
+ * A landing page reserved for one channel's ads, for ads that lost their parameters:
38
+ * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
39
+ * that names its landing pages differently replaces this.
40
+ */
41
+ declare const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
42
+ type ReferrerMedium = 'organic' | 'social' | 'video';
43
+ /**
44
+ * Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
45
+ * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
46
+ * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
47
+ * never an open tail, so `google.com.evil.io` is not Google.
48
+ */
49
+ 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]];
50
+ /**
51
+ * Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
52
+ * visitor is bounced through and back from, and the local dev host. A product appends its own
53
+ * hostnames — a session that starts from an internal link after the session timeout refers to
54
+ * them. POSIX regular expressions over the lower-cased host.
55
+ */
56
+ declare const REFERRERS_NOT_A_TOUCH: readonly [string, string, string, string, string, string];
57
+ /** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
58
+ declare const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
59
+ declare const DISPLAY_MEDIUMS: readonly ['display', 'banner', 'expandable', 'interstitial'];
60
+ declare const EMAIL_MEDIUMS: readonly ['email', 'e-mail', 'e_mail', 'e mail'];
61
+ /** Where a touch came from: a tracked session, or a report by the user or staff. */
62
+ declare const TOUCH_SOURCES: readonly ['tracked', 'reported'];
63
+ type TouchSource = (typeof TOUCH_SOURCES)[number];
64
+ /**
65
+ * How a reported touch was learned:
66
+ * - survey: the user answered "how did you hear about us" (onboarding, checkout)
67
+ * - promo_code: the user redeemed a code that belongs to a channel
68
+ * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
69
+ * - manual: staff recorded what a customer told them
70
+ */
71
+ declare const REPORTED_TOUCH_KINDS: readonly ['survey', 'promo_code', 'phone', 'manual'];
72
+ type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];
73
+ /**
74
+ * How much a touch is worth against another when attribution has to choose between sessions;
75
+ * lower wins, and the latest wins among equals. Derived in the views, never stored, so
76
+ * renumbering is a view regeneration.
77
+ *
78
+ * This ranks touches against each other. Within one session the rules that name its channel have
79
+ * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
80
+ * and the first that says something wins; the session's priority is then the tier of that rule.
81
+ * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
82
+ * later one is credited, while one session carrying both is named by its utm.
83
+ */
84
+ declare const TOUCH_PRIORITY: {
85
+ /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
86
+ readonly campaign: 1;
87
+ /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
88
+ readonly verified: 1;
89
+ /** the browser said where the visitor came from; nobody chose it */
90
+ readonly referrer: 2;
91
+ /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
92
+ readonly claimed: 3;
93
+ };
94
+ /** Which reported kinds are staff facts and which are the user's claims. */
95
+ declare const REPORTED_TOUCH_PRIORITY: {
96
+ readonly phone: 1;
97
+ readonly manual: 1;
98
+ readonly survey: 3;
99
+ readonly promo_code: 3;
100
+ };
101
+ //#endregion
102
+ 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 };
103
+ //# 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;KAsBD,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,103 @@
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
+ type Channel = (typeof CHANNELS)[number];
16
+ /** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
17
+ declare const CHANNEL_GROUPS: readonly ['direct', 'paid_search', 'paid_social', 'paid_other', 'display', 'organic_search', 'organic_social', 'organic_video', 'referral', 'email', 'affiliate', 'unassigned'];
18
+ type ChannelGroup = (typeof CHANNEL_GROUPS)[number];
19
+ /** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
20
+ declare const SOURCE_ALIASES: {
21
+ readonly fb: 'meta';
22
+ readonly ig: 'meta';
23
+ readonly an: 'meta';
24
+ readonly msg: 'meta';
25
+ readonly facebook: 'meta';
26
+ readonly instagram: 'meta';
27
+ readonly bing: 'microsoft';
28
+ readonly twitter: 'x';
29
+ };
30
+ /**
31
+ * Which click id belongs to which channel, in priority order. Every key is a field this SDK
32
+ * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
33
+ * browser ids, present with or without a click.
34
+ */
35
+ 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"]];
36
+ /**
37
+ * A landing page reserved for one channel's ads, for ads that lost their parameters:
38
+ * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
39
+ * that names its landing pages differently replaces this.
40
+ */
41
+ declare const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
42
+ type ReferrerMedium = 'organic' | 'social' | 'video';
43
+ /**
44
+ * Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
45
+ * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
46
+ * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
47
+ * never an open tail, so `google.com.evil.io` is not Google.
48
+ */
49
+ 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]];
50
+ /**
51
+ * Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
52
+ * visitor is bounced through and back from, and the local dev host. A product appends its own
53
+ * hostnames — a session that starts from an internal link after the session timeout refers to
54
+ * them. POSIX regular expressions over the lower-cased host.
55
+ */
56
+ declare const REFERRERS_NOT_A_TOUCH: readonly [string, string, string, string, string, string];
57
+ /** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
58
+ declare const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
59
+ declare const DISPLAY_MEDIUMS: readonly ['display', 'banner', 'expandable', 'interstitial'];
60
+ declare const EMAIL_MEDIUMS: readonly ['email', 'e-mail', 'e_mail', 'e mail'];
61
+ /** Where a touch came from: a tracked session, or a report by the user or staff. */
62
+ declare const TOUCH_SOURCES: readonly ['tracked', 'reported'];
63
+ type TouchSource = (typeof TOUCH_SOURCES)[number];
64
+ /**
65
+ * How a reported touch was learned:
66
+ * - survey: the user answered "how did you hear about us" (onboarding, checkout)
67
+ * - promo_code: the user redeemed a code that belongs to a channel
68
+ * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
69
+ * - manual: staff recorded what a customer told them
70
+ */
71
+ declare const REPORTED_TOUCH_KINDS: readonly ['survey', 'promo_code', 'phone', 'manual'];
72
+ type ReportedTouchKind = (typeof REPORTED_TOUCH_KINDS)[number];
73
+ /**
74
+ * How much a touch is worth against another when attribution has to choose between sessions;
75
+ * lower wins, and the latest wins among equals. Derived in the views, never stored, so
76
+ * renumbering is a view regeneration.
77
+ *
78
+ * This ranks touches against each other. Within one session the rules that name its channel have
79
+ * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
80
+ * and the first that says something wins; the session's priority is then the tier of that rule.
81
+ * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
82
+ * later one is credited, while one session carrying both is named by its utm.
83
+ */
84
+ declare const TOUCH_PRIORITY: {
85
+ /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
86
+ readonly campaign: 1;
87
+ /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
88
+ readonly verified: 1;
89
+ /** the browser said where the visitor came from; nobody chose it */
90
+ readonly referrer: 2;
91
+ /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
92
+ readonly claimed: 3;
93
+ };
94
+ /** Which reported kinds are staff facts and which are the user's claims. */
95
+ declare const REPORTED_TOUCH_PRIORITY: {
96
+ readonly phone: 1;
97
+ readonly manual: 1;
98
+ readonly survey: 3;
99
+ readonly promo_code: 3;
100
+ };
101
+ //#endregion
102
+ 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 };
103
+ //# 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;KAsBD,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,257 @@
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
+ ];
35
+ /** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
36
+ const CHANNEL_GROUPS = [
37
+ "direct",
38
+ "paid_search",
39
+ "paid_social",
40
+ "paid_other",
41
+ "display",
42
+ "organic_search",
43
+ "organic_social",
44
+ "organic_video",
45
+ "referral",
46
+ "email",
47
+ "affiliate",
48
+ "unassigned"
49
+ ];
50
+ /** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
51
+ const SOURCE_ALIASES = {
52
+ fb: "meta",
53
+ ig: "meta",
54
+ an: "meta",
55
+ msg: "meta",
56
+ facebook: "meta",
57
+ instagram: "meta",
58
+ bing: "microsoft",
59
+ twitter: "x"
60
+ };
61
+ /**
62
+ * Which click id belongs to which channel, in priority order. Every key is a field this SDK
63
+ * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
64
+ * browser ids, present with or without a click.
65
+ */
66
+ const CLICK_ID_CHANNELS = [
67
+ ["fbclid", "meta"],
68
+ ["fbc", "meta"],
69
+ ["gclid", "google"],
70
+ ["gbraid", "google"],
71
+ ["wbraid", "google"],
72
+ ["gad_source", "google"],
73
+ ["gad_campaignid", "google"],
74
+ ["dclid", "dv360"],
75
+ ["msclkid", "microsoft"],
76
+ ["ttclid", "tiktok"],
77
+ ["rdt_cid", "reddit"],
78
+ ["li_fat_id", "linkedin"],
79
+ ["sccid", "snapchat"],
80
+ ["twclid", "x"],
81
+ ["ko_click_id", "kakao"],
82
+ ["yclid", "yandex"]
83
+ ];
84
+ /**
85
+ * A landing page reserved for one channel's ads, for ads that lost their parameters:
86
+ * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
87
+ * that names its landing pages differently replaces this.
88
+ */
89
+ const AD_LANDING_PAGE = "^(?:https?://[^/]+)?/lp/([a-z]+)(?:[/?#]|$)";
90
+ /**
91
+ * Referrer hosts that name a channel, as POSIX regular expressions over the lower-cased host,
92
+ * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
93
+ * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
94
+ * never an open tail, so `google.com.evil.io` is not Google.
95
+ */
96
+ const REFERRER_SITES = [
97
+ [
98
+ "google",
99
+ "organic",
100
+ String.raw`(^|\.)google\.[a-z]{2,}(\.[a-z]{2,3})?$`
101
+ ],
102
+ [
103
+ "microsoft",
104
+ "organic",
105
+ String.raw`(^|\.)bing\.com$`
106
+ ],
107
+ [
108
+ "yahoo",
109
+ "organic",
110
+ String.raw`(^|\.)yahoo\.[a-z]{2,}(\.[a-z]{2,3})?$`
111
+ ],
112
+ [
113
+ "duckduckgo",
114
+ "organic",
115
+ String.raw`(^|\.)duckduckgo\.com$`
116
+ ],
117
+ [
118
+ "baidu",
119
+ "organic",
120
+ String.raw`(^|\.)baidu\.com$`
121
+ ],
122
+ [
123
+ "yandex",
124
+ "organic",
125
+ String.raw`(^|\.)yandex\.[a-z]{2,}(\.[a-z]{2,3})?$`
126
+ ],
127
+ [
128
+ "ecosia",
129
+ "organic",
130
+ String.raw`(^|\.)ecosia\.org$`
131
+ ],
132
+ [
133
+ "naver",
134
+ "organic",
135
+ String.raw`(^|\.)naver\.com$`
136
+ ],
137
+ [
138
+ "brave",
139
+ "organic",
140
+ String.raw`^search\.brave\.com$`
141
+ ],
142
+ [
143
+ "meta",
144
+ "social",
145
+ String.raw`(^|\.)(facebook\.com|instagram\.com|fb\.com|threads\.net)$`
146
+ ],
147
+ [
148
+ "x",
149
+ "social",
150
+ String.raw`(^|\.)(twitter\.com|x\.com|t\.co)$`
151
+ ],
152
+ [
153
+ "linkedin",
154
+ "social",
155
+ String.raw`(^|\.)(linkedin\.com|lnkd\.in)$`
156
+ ],
157
+ [
158
+ "reddit",
159
+ "social",
160
+ String.raw`(^|\.)reddit\.com$`
161
+ ],
162
+ [
163
+ "tiktok",
164
+ "social",
165
+ String.raw`(^|\.)tiktok\.com$`
166
+ ],
167
+ [
168
+ "pinterest",
169
+ "social",
170
+ String.raw`(^|\.)pinterest\.[a-z]{2,}(\.[a-z]{2,3})?$`
171
+ ],
172
+ [
173
+ "snapchat",
174
+ "social",
175
+ String.raw`(^|\.)snapchat\.com$`
176
+ ],
177
+ [
178
+ "youtube",
179
+ "video",
180
+ String.raw`(^|\.)(youtube\.com|youtu\.be)$`
181
+ ]
182
+ ];
183
+ /**
184
+ * Referrer hosts that are navigation, not acquisition: the payment and sign-in providers a
185
+ * visitor is bounced through and back from, and the local dev host. A product appends its own
186
+ * hostnames — a session that starts from an internal link after the session timeout refers to
187
+ * them. POSIX regular expressions over the lower-cased host.
188
+ */
189
+ const REFERRERS_NOT_A_TOUCH = [
190
+ String.raw`^localhost(:|$)`,
191
+ String.raw`(^|\.)stripe\.com$`,
192
+ String.raw`^(pay|accounts)\.google\.com$`,
193
+ String.raw`^(appleid|apps)\.apple\.com$`,
194
+ String.raw`^play\.google\.com$`,
195
+ String.raw`^login\.microsoftonline\.com$`
196
+ ];
197
+ /** GA4's paid mediums: cpc, cpm, ppc, retargeting, paid_social, … */
198
+ const PAID_MEDIUM = "^(.*cp.*|ppc|retargeting|paid.*)$";
199
+ const DISPLAY_MEDIUMS = [
200
+ "display",
201
+ "banner",
202
+ "expandable",
203
+ "interstitial"
204
+ ];
205
+ const EMAIL_MEDIUMS = [
206
+ "email",
207
+ "e-mail",
208
+ "e_mail",
209
+ "e mail"
210
+ ];
211
+ /** Where a touch came from: a tracked session, or a report by the user or staff. */
212
+ const TOUCH_SOURCES = ["tracked", "reported"];
213
+ /**
214
+ * How a reported touch was learned:
215
+ * - survey: the user answered "how did you hear about us" (onboarding, checkout)
216
+ * - promo_code: the user redeemed a code that belongs to a channel
217
+ * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
218
+ * - manual: staff recorded what a customer told them
219
+ */
220
+ const REPORTED_TOUCH_KINDS = [
221
+ "survey",
222
+ "promo_code",
223
+ "phone",
224
+ "manual"
225
+ ];
226
+ /**
227
+ * How much a touch is worth against another when attribution has to choose between sessions;
228
+ * lower wins, and the latest wins among equals. Derived in the views, never stored, so
229
+ * renumbering is a view regeneration.
230
+ *
231
+ * This ranks touches against each other. Within one session the rules that name its channel have
232
+ * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
233
+ * and the first that says something wins; the session's priority is then the tier of that rule.
234
+ * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
235
+ * later one is credited, while one session carrying both is named by its utm.
236
+ */
237
+ const TOUCH_PRIORITY = {
238
+ /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
239
+ campaign: 1,
240
+ /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
241
+ verified: 1,
242
+ /** the browser said where the visitor came from; nobody chose it */
243
+ referrer: 2,
244
+ /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
245
+ claimed: 3
246
+ };
247
+ /** Which reported kinds are staff facts and which are the user's claims. */
248
+ const REPORTED_TOUCH_PRIORITY = {
249
+ phone: TOUCH_PRIORITY.verified,
250
+ manual: TOUCH_PRIORITY.verified,
251
+ survey: TOUCH_PRIORITY.claimed,
252
+ promo_code: TOUCH_PRIORITY.claimed
253
+ };
254
+ //#endregion
255
+ 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 };
256
+
257
+ //# 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] 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;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.9.0",
3
+ "version": "8.10.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",