@shware/analytics 8.11.0 → 8.13.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.
Files changed (41) hide show
  1. package/dist/attribution/classify.cjs +128 -0
  2. package/dist/attribution/classify.cjs.map +1 -0
  3. package/dist/attribution/classify.d.cts +62 -0
  4. package/dist/attribution/classify.d.cts.map +1 -0
  5. package/dist/attribution/classify.d.mts +62 -0
  6. package/dist/attribution/classify.d.mts.map +1 -0
  7. package/dist/attribution/classify.mjs +126 -0
  8. package/dist/attribution/classify.mjs.map +1 -0
  9. package/dist/attribution/index.cjs +23 -274
  10. package/dist/attribution/index.d.cts +3 -108
  11. package/dist/attribution/index.d.mts +3 -108
  12. package/dist/attribution/index.mjs +3 -258
  13. package/dist/attribution/vocabulary.cjs +449 -0
  14. package/dist/attribution/vocabulary.cjs.map +1 -0
  15. package/dist/attribution/vocabulary.d.cts +154 -0
  16. package/dist/attribution/vocabulary.d.cts.map +1 -0
  17. package/dist/attribution/vocabulary.d.mts +154 -0
  18. package/dist/attribution/vocabulary.d.mts.map +1 -0
  19. package/dist/attribution/vocabulary.mjs +430 -0
  20. package/dist/attribution/vocabulary.mjs.map +1 -0
  21. package/dist/index.d.cts +1 -1
  22. package/dist/index.d.mts +1 -1
  23. package/dist/third-parties/google-analytics.d.cts +1 -1
  24. package/dist/third-parties/google-analytics.d.mts +1 -1
  25. package/dist/third-parties/linkedin-insight-tag.d.cts +1 -1
  26. package/dist/third-parties/linkedin-insight-tag.d.mts +1 -1
  27. package/dist/third-parties/meta-pixel.d.cts +1 -1
  28. package/dist/third-parties/meta-pixel.d.mts +1 -1
  29. package/dist/third-parties/microsoft-uet.d.cts +1 -1
  30. package/dist/third-parties/microsoft-uet.d.mts +1 -1
  31. package/dist/third-parties/openai-pixel.d.cts +1 -1
  32. package/dist/third-parties/openai-pixel.d.mts +1 -1
  33. package/dist/third-parties/reddit-pixel.d.cts +1 -1
  34. package/dist/third-parties/reddit-pixel.d.mts +1 -1
  35. package/dist/visitor/types.d.cts +1 -1
  36. package/dist/visitor/types.d.mts +1 -1
  37. package/package.json +1 -1
  38. package/dist/attribution/index.cjs.map +0 -1
  39. package/dist/attribution/index.d.cts.map +0 -1
  40. package/dist/attribution/index.d.mts.map +0 -1
  41. package/dist/attribution/index.mjs.map +0 -1
@@ -0,0 +1,430 @@
1
+ //#region src/attribution/vocabulary.ts
2
+ /**
3
+ * The vocabulary attribution is built from, shared by every product's `session` table and by the
4
+ * dashboards that read it. Data for `classifyTouch` (./classify), which turns it into a channel;
5
+ * a product's dashboards read the same names back. What stays with the product is its own hostnames
6
+ * (referrer exclusions) and its landing-page conventions.
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
+ "chatgpt",
36
+ "perplexity",
37
+ "gemini",
38
+ "claude",
39
+ "copilot",
40
+ "grok",
41
+ "deepseek",
42
+ "doubao",
43
+ "kimi",
44
+ "qwen",
45
+ "yuanbao",
46
+ "ernie",
47
+ "zhipu",
48
+ "referral_program"
49
+ ];
50
+ /** GA4's default channel groups, as identifiers; a dashboard maps them to display names. */
51
+ const CHANNEL_GROUPS = [
52
+ "direct",
53
+ "paid_search",
54
+ "paid_social",
55
+ "paid_other",
56
+ "display",
57
+ "organic_search",
58
+ "organic_social",
59
+ "organic_video",
60
+ "organic_ai",
61
+ "referral",
62
+ "email",
63
+ "affiliate",
64
+ "unassigned"
65
+ ];
66
+ /** `utm_source` spellings that mean the same channel: Meta's `{{site_source_name}}` values and the usual synonyms. */
67
+ const SOURCE_ALIASES = {
68
+ fb: "meta",
69
+ ig: "meta",
70
+ an: "meta",
71
+ msg: "meta",
72
+ facebook: "meta",
73
+ instagram: "meta",
74
+ bing: "microsoft",
75
+ twitter: "x",
76
+ "google ads": "google",
77
+ googleads: "google",
78
+ adwords: "google",
79
+ "chatgpt.com": "chatgpt",
80
+ "chat.openai.com": "chatgpt",
81
+ openai: "chatgpt",
82
+ "perplexity.ai": "perplexity",
83
+ "claude.ai": "claude",
84
+ "copilot.com": "copilot",
85
+ "deepseek.com": "deepseek",
86
+ "doubao.com": "doubao",
87
+ "kimi.com": "kimi"
88
+ };
89
+ /**
90
+ * Which click id belongs to which channel, in priority order. Every key is a field this SDK
91
+ * collects (`AdvertisingInfo`); `fbp` and `rdt_uuid` are deliberately absent — they are pixel
92
+ * browser ids, present with or without a click.
93
+ */
94
+ const CLICK_ID_CHANNELS = [
95
+ ["fbclid", "meta"],
96
+ ["fbc", "meta"],
97
+ ["gclid", "google"],
98
+ ["gbraid", "google"],
99
+ ["wbraid", "google"],
100
+ ["gad_source", "google"],
101
+ ["gad_campaignid", "google"],
102
+ ["dclid", "dv360"],
103
+ ["msclkid", "microsoft"],
104
+ ["ttclid", "tiktok"],
105
+ ["rdt_cid", "reddit"],
106
+ ["li_fat_id", "linkedin"],
107
+ ["sccid", "snapchat"],
108
+ ["twclid", "x"],
109
+ ["ko_click_id", "kakao"],
110
+ ["yclid", "yandex"]
111
+ ];
112
+ /**
113
+ * A landing page reserved for one channel's ads, for ads that lost their parameters:
114
+ * `/lp/<channel>`, with or without host, query and hash; the capture is the channel. A product
115
+ * that names its landing pages differently replaces this.
116
+ */
117
+ const AD_LANDING_PAGE = /^(?:https?:\/\/[^/]+)?\/lp\/([a-z]+)(?:[/?#]|$)/;
118
+ /**
119
+ * Referrer hosts that name a channel, as regular expressions over the lower-cased host,
120
+ * with the medium GA4 gives that kind of site. Anything else that refers is `referral`, kept as
121
+ * its host. A country TLD is one or two labels (`google.com`, `google.co.uk`, `google.com.hk`),
122
+ * never an open tail, so `google.com.evil.io` is not Google. In match order: the AI assistants
123
+ * first, because `gemini.google.com`, `copilot.microsoft.com` and `yiyan.baidu.com` would
124
+ * otherwise be Google, Microsoft and Baidu search.
125
+ */
126
+ const REFERRER_SITES = [
127
+ [
128
+ "chatgpt",
129
+ "ai",
130
+ /(^|\.)(chatgpt\.com|chat\.openai\.com)$/
131
+ ],
132
+ [
133
+ "perplexity",
134
+ "ai",
135
+ /(^|\.)perplexity\.ai$/
136
+ ],
137
+ [
138
+ "gemini",
139
+ "ai",
140
+ /^gemini\.google\.com$/
141
+ ],
142
+ [
143
+ "claude",
144
+ "ai",
145
+ /(^|\.)claude\.ai$/
146
+ ],
147
+ [
148
+ "copilot",
149
+ "ai",
150
+ /^copilot\.microsoft\.com$|(^|\.)copilot\.com$/
151
+ ],
152
+ [
153
+ "grok",
154
+ "ai",
155
+ /(^|\.)(grok\.com|x\.ai)$/
156
+ ],
157
+ [
158
+ "deepseek",
159
+ "ai",
160
+ /(^|\.)deepseek\.com$/
161
+ ],
162
+ [
163
+ "doubao",
164
+ "ai",
165
+ /(^|\.)doubao\.com$/
166
+ ],
167
+ [
168
+ "kimi",
169
+ "ai",
170
+ /(^|\.)(kimi\.com|kimi\.moonshot\.cn|moonshot\.cn)$/
171
+ ],
172
+ [
173
+ "qwen",
174
+ "ai",
175
+ /^tongyi\.aliyun\.com$|(^|\.)(tongyi\.com|qianwen\.com|qwen\.ai)$/
176
+ ],
177
+ [
178
+ "yuanbao",
179
+ "ai",
180
+ /^yuanbao\.tencent\.com$/
181
+ ],
182
+ [
183
+ "ernie",
184
+ "ai",
185
+ /^yiyan\.baidu\.com$|(^|\.)ernie\.baidu\.com$/
186
+ ],
187
+ [
188
+ "zhipu",
189
+ "ai",
190
+ /(^|\.)(chatglm\.cn|zhipuai\.cn|bigmodel\.cn)$/
191
+ ],
192
+ [
193
+ "google",
194
+ "organic",
195
+ /(^|\.)google\.[a-z]{2,}(\.[a-z]{2,3})?$/
196
+ ],
197
+ [
198
+ "microsoft",
199
+ "organic",
200
+ /(^|\.)bing\.com$/
201
+ ],
202
+ [
203
+ "yahoo",
204
+ "organic",
205
+ /(^|\.)yahoo\.[a-z]{2,}(\.[a-z]{2,3})?$/
206
+ ],
207
+ [
208
+ "duckduckgo",
209
+ "organic",
210
+ /(^|\.)duckduckgo\.com$/
211
+ ],
212
+ [
213
+ "baidu",
214
+ "organic",
215
+ /(^|\.)baidu\.com$/
216
+ ],
217
+ [
218
+ "yandex",
219
+ "organic",
220
+ /(^|\.)yandex\.[a-z]{2,}(\.[a-z]{2,3})?$/
221
+ ],
222
+ [
223
+ "ecosia",
224
+ "organic",
225
+ /(^|\.)ecosia\.org$/
226
+ ],
227
+ [
228
+ "naver",
229
+ "organic",
230
+ /(^|\.)naver\.com$/
231
+ ],
232
+ [
233
+ "brave",
234
+ "organic",
235
+ /^search\.brave\.com$/
236
+ ],
237
+ [
238
+ "meta",
239
+ "social",
240
+ /(^|\.)(facebook\.com|instagram\.com|fb\.com|threads\.net)$/
241
+ ],
242
+ [
243
+ "x",
244
+ "social",
245
+ /(^|\.)(twitter\.com|x\.com|t\.co)$/
246
+ ],
247
+ [
248
+ "linkedin",
249
+ "social",
250
+ /(^|\.)(linkedin\.com|lnkd\.in)$/
251
+ ],
252
+ [
253
+ "reddit",
254
+ "social",
255
+ /(^|\.)reddit\.com$/
256
+ ],
257
+ [
258
+ "tiktok",
259
+ "social",
260
+ /(^|\.)tiktok\.com$/
261
+ ],
262
+ [
263
+ "pinterest",
264
+ "social",
265
+ /(^|\.)pinterest\.[a-z]{2,}(\.[a-z]{2,3})?$/
266
+ ],
267
+ [
268
+ "snapchat",
269
+ "social",
270
+ /(^|\.)snapchat\.com$/
271
+ ],
272
+ [
273
+ "youtube",
274
+ "video",
275
+ /(^|\.)(youtube\.com|youtu\.be)$/
276
+ ]
277
+ ];
278
+ /**
279
+ * Referrer hosts that are navigation, not acquisition, when a session happens to start on the way
280
+ * back from them: the local dev host; the payment providers a visitor is bounced through; the
281
+ * sign-in providers whose login lives on a host of its own (Google, Apple, Microsoft, WeChat,
282
+ * Kakao, LINE, Naver, Yahoo, Twitch, X's OAuth 1.0a endpoint); and the hosted auth services a
283
+ * product may sit behind (Auth0, Okta, Supabase, Firebase, Clerk). A product appends its own
284
+ * hostnames — a session that starts from an internal link after the session timeout refers to
285
+ * them. Matched before `REFERRER_SITES`, so `nid.naver.com` and `login.yahoo.com` are not read as
286
+ * a search. Providers whose login shares the host with their content — Facebook, X's OAuth 2.0,
287
+ * LinkedIn, GitHub, Discord — cannot be told apart by host (referrer policies strip the path) and
288
+ * are left as the referrers they usually are. Regular expressions over the lower-cased host.
289
+ */
290
+ const REFERRERS_NOT_A_TOUCH = [
291
+ /^localhost(:|$)/,
292
+ /(^|\.)stripe\.com$/,
293
+ /^pay\.google\.com$/,
294
+ /(^|\.)paypal\.com$/,
295
+ /(^|\.)alipay\.com$/,
296
+ /(^|\.)paddle\.com$/,
297
+ /(^|\.)lemonsqueezy\.com$/,
298
+ /^apps\.apple\.com$/,
299
+ /^play\.google\.com$/,
300
+ /^accounts\.google\.com$/,
301
+ /^appleid\.apple\.com$/,
302
+ /^login\.(microsoftonline|live)\.com$/,
303
+ /^open\.weixin\.qq\.com$/,
304
+ /^(kauth|accounts)\.kakao\.com$/,
305
+ /^access\.line\.me$/,
306
+ /^nid\.naver\.com$/,
307
+ /^login\.yahoo\.com$/,
308
+ /^id\.twitch\.tv$/,
309
+ /^api\.twitter\.com$/,
310
+ /(^|\.)auth0\.com$/,
311
+ /(^|\.)okta\.com$/,
312
+ /(^|\.)supabase\.co$/,
313
+ /(^|\.)firebaseapp\.com$/,
314
+ /(^|\.)clerk\.accounts\.dev$/
315
+ ];
316
+ /** GA4's paid mediums — cpc, cpm, ppc, retargeting, paid_social, … — plus Performance Max. */
317
+ const PAID_MEDIUM = /^(.*cp.*|ppc|retargeting|paid.*|pmax|performance_max)$/;
318
+ /**
319
+ * Meta's `{{placement}}` values, lower-cased, which an ad URL template of `utm_medium={{placement}}`
320
+ * puts in the medium. Only an ad carries one — an organic post arrives as a referrer, with no utm
321
+ * at all — so a medium in this list is a paid Meta click whatever the source says (a template with
322
+ * `utm_source=meta-websitekeyinfo` was seen). Listed one by one rather than matched by prefix, so
323
+ * that a hand-tagged `instagram_stories` post cannot be mistaken for an ad only because of how it
324
+ * is spelled … which means a placement Meta adds later shows up as unassigned until it is added
325
+ * here. Meta's documented values plus the ones seen in the wild (`facebook_mobile_reels`,
326
+ * `facebook_notification`, `an`), and the literal macro for a template that did not expand it.
327
+ */
328
+ const META_PLACEMENTS = [
329
+ "facebook_desktop_feed",
330
+ "facebook_mobile_feed",
331
+ "facebook_mobile_reels",
332
+ "facebook_reels",
333
+ "facebook_reels_overlay",
334
+ "facebook_right_column",
335
+ "facebook_marketplace",
336
+ "facebook_video_feeds",
337
+ "facebook_stories",
338
+ "facebook_search",
339
+ "facebook_instream_video",
340
+ "facebook_instant_article",
341
+ "facebook_groups_feed",
342
+ "facebook_profile_feed",
343
+ "facebook_notification",
344
+ "facebook_notifications",
345
+ "facebook_business_explore",
346
+ "instagram_feed",
347
+ "instagram_stories",
348
+ "instagram_reels",
349
+ "instagram_reels_overlay",
350
+ "instagram_explore",
351
+ "instagram_explore_home",
352
+ "instagram_search",
353
+ "instagram_shop",
354
+ "instagram_profile_feed",
355
+ "instagram_profile_reels",
356
+ "instagram_igtv",
357
+ "messenger_inbox",
358
+ "messenger_stories",
359
+ "messenger_sponsored_messages",
360
+ "threads_feed",
361
+ "whatsapp_status",
362
+ "audience_network_classic",
363
+ "audience_network_rewarded_video",
364
+ "audience_network_native_banner_and_interstitial",
365
+ "an",
366
+ "others",
367
+ "{{placement}}"
368
+ ];
369
+ const DISPLAY_MEDIUMS = [
370
+ "display",
371
+ "banner",
372
+ "expandable",
373
+ "interstitial"
374
+ ];
375
+ /** GA4's email spellings, as a source or a medium. */
376
+ const EMAIL_MEDIUMS = [
377
+ "email",
378
+ "e-mail",
379
+ "e_mail",
380
+ "e mail"
381
+ ];
382
+ /** A medium that says email or newsletter anywhere in it: `outbound email`, `cold_email`, `newsletter`, and GA4's four. */
383
+ const EMAIL_MEDIUM = /(^|[^a-z])(e[-_ ]?mail|newsletter)([^a-z]|$)/;
384
+ /** Where a touch came from: a tracked session, or a report by the user or staff. */
385
+ const TOUCH_SOURCES = ["tracked", "reported"];
386
+ /**
387
+ * How a reported touch was learned:
388
+ * - survey: the user answered "how did you hear about us" (onboarding, checkout)
389
+ * - promo_code: the user redeemed a code that belongs to a channel
390
+ * - phone: a call came in on a channel's dedicated number, marked by staff or the phone system
391
+ * - manual: staff recorded what a customer told them
392
+ */
393
+ const REPORTED_TOUCH_KINDS = [
394
+ "survey",
395
+ "promo_code",
396
+ "phone",
397
+ "manual"
398
+ ];
399
+ /**
400
+ * How much a touch is worth against another when attribution has to choose between sessions;
401
+ * lower wins, and the latest wins among equals. Stored on the session when it is classified, so
402
+ * renumbering means reclassifying.
403
+ *
404
+ * This ranks touches against each other. Within one session the rules that name its channel have
405
+ * their own order — `utm_source`, then a click id, then the ad landing page, then the referrer —
406
+ * and the first that says something wins; the session's priority is then the tier of that rule.
407
+ * So two sessions tagged with utm and gclid respectively are equal here (both `campaign`) and the
408
+ * later one is credited, while one session carrying both is named by its utm.
409
+ */
410
+ const TOUCH_PRIORITY = {
411
+ /** utm, click id, ad landing page: someone tagged that link (in that order within a session) */
412
+ campaign: 1,
413
+ /** a reported touch staff stand behind: a call on a channel's number, a recorded conversation */
414
+ verified: 1,
415
+ /** the browser said where the visitor came from; nobody chose it */
416
+ referrer: 2,
417
+ /** a reported touch that is the user's claim: a survey answer, a code that may have been shared */
418
+ claimed: 3
419
+ };
420
+ /** Which reported kinds are staff facts and which are the user's claims. */
421
+ const REPORTED_TOUCH_PRIORITY = {
422
+ phone: TOUCH_PRIORITY.verified,
423
+ manual: TOUCH_PRIORITY.verified,
424
+ survey: TOUCH_PRIORITY.claimed,
425
+ promo_code: TOUCH_PRIORITY.claimed
426
+ };
427
+ //#endregion
428
+ export { AD_LANDING_PAGE, CHANNELS, CHANNEL_GROUPS, CLICK_ID_CHANNELS, DIRECT_CHANNEL, DISPLAY_MEDIUMS, EMAIL_MEDIUM, EMAIL_MEDIUMS, MEDIUM_NOT_SET, META_PLACEMENTS, NO_MEDIUM, PAID_MEDIUM, REFERRERS_NOT_A_TOUCH, REFERRER_SITES, REPORTED_TOUCH_KINDS, REPORTED_TOUCH_PRIORITY, SOURCE_ALIASES, TOUCH_PRIORITY, TOUCH_SOURCES };
429
+
430
+ //# sourceMappingURL=vocabulary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocabulary.mjs","names":[],"sources":["../../src/attribution/vocabulary.ts"],"sourcesContent":["import type { AdvertisingInfo } from '../track/types';\n\n/**\n * The vocabulary attribution is built from, shared by every product's `session` table and by the\n * dashboards that read it. Data for `classifyTouch` (./classify), which turns it into a channel;\n * a product's dashboards read the same names back. What stays with the product is its own hostnames\n * (referrer exclusions) and its landing-page conventions.\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 /** AI assistants that send people to sites: ChatGPT tags its links `utm_source=chatgpt.com`, the\n * others show as a referrer. Their own channel group, `organic_ai`, since GA4's default groups\n * would file them under Referral / Unassigned and the question \"how much does AI bring\" comes up. */\n 'chatgpt',\n 'perplexity',\n 'gemini',\n 'claude',\n 'copilot',\n 'grok',\n /** and the Chinese ones — DeepSeek, 豆包, Kimi, 通义, 腾讯元宝, 文心一言, 智谱清言 */\n 'deepseek',\n 'doubao',\n 'kimi',\n 'qwen',\n 'yuanbao',\n 'ernie',\n 'zhipu',\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 /** not in GA4's default grouping: sessions an AI assistant sent, by referrer or by ChatGPT's utm */\n 'organic_ai',\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 'google ads': 'google',\n googleads: 'google',\n adwords: 'google',\n 'chatgpt.com': 'chatgpt',\n 'chat.openai.com': 'chatgpt',\n openai: 'chatgpt',\n 'perplexity.ai': 'perplexity',\n 'claude.ai': 'claude',\n 'copilot.com': 'copilot',\n 'deepseek.com': 'deepseek',\n 'doubao.com': 'doubao',\n 'kimi.com': 'kimi',\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' | 'ai';\n\n/**\n * Referrer hosts that name a channel, as 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. In match order: the AI assistants\n * first, because `gemini.google.com`, `copilot.microsoft.com` and `yiyan.baidu.com` would\n * otherwise be Google, Microsoft and Baidu search.\n */\nexport const REFERRER_SITES = [\n ['chatgpt', 'ai', /(^|\\.)(chatgpt\\.com|chat\\.openai\\.com)$/],\n ['perplexity', 'ai', /(^|\\.)perplexity\\.ai$/],\n ['gemini', 'ai', /^gemini\\.google\\.com$/],\n ['claude', 'ai', /(^|\\.)claude\\.ai$/],\n ['copilot', 'ai', /^copilot\\.microsoft\\.com$|(^|\\.)copilot\\.com$/],\n ['grok', 'ai', /(^|\\.)(grok\\.com|x\\.ai)$/],\n ['deepseek', 'ai', /(^|\\.)deepseek\\.com$/],\n ['doubao', 'ai', /(^|\\.)doubao\\.com$/],\n ['kimi', 'ai', /(^|\\.)(kimi\\.com|kimi\\.moonshot\\.cn|moonshot\\.cn)$/],\n ['qwen', 'ai', /^tongyi\\.aliyun\\.com$|(^|\\.)(tongyi\\.com|qianwen\\.com|qwen\\.ai)$/],\n ['yuanbao', 'ai', /^yuanbao\\.tencent\\.com$/],\n ['ernie', 'ai', /^yiyan\\.baidu\\.com$|(^|\\.)ernie\\.baidu\\.com$/],\n ['zhipu', 'ai', /(^|\\.)(chatglm\\.cn|zhipuai\\.cn|bigmodel\\.cn)$/],\n ['google', 'organic', /(^|\\.)google\\.[a-z]{2,}(\\.[a-z]{2,3})?$/],\n ['microsoft', 'organic', /(^|\\.)bing\\.com$/],\n ['yahoo', 'organic', /(^|\\.)yahoo\\.[a-z]{2,}(\\.[a-z]{2,3})?$/],\n ['duckduckgo', 'organic', /(^|\\.)duckduckgo\\.com$/],\n ['baidu', 'organic', /(^|\\.)baidu\\.com$/],\n ['yandex', 'organic', /(^|\\.)yandex\\.[a-z]{2,}(\\.[a-z]{2,3})?$/],\n ['ecosia', 'organic', /(^|\\.)ecosia\\.org$/],\n ['naver', 'organic', /(^|\\.)naver\\.com$/],\n ['brave', 'organic', /^search\\.brave\\.com$/],\n ['meta', 'social', /(^|\\.)(facebook\\.com|instagram\\.com|fb\\.com|threads\\.net)$/],\n ['x', 'social', /(^|\\.)(twitter\\.com|x\\.com|t\\.co)$/],\n ['linkedin', 'social', /(^|\\.)(linkedin\\.com|lnkd\\.in)$/],\n ['reddit', 'social', /(^|\\.)reddit\\.com$/],\n ['tiktok', 'social', /(^|\\.)tiktok\\.com$/],\n ['pinterest', 'social', /(^|\\.)pinterest\\.[a-z]{2,}(\\.[a-z]{2,3})?$/],\n ['snapchat', 'social', /(^|\\.)snapchat\\.com$/],\n ['youtube', 'video', /(^|\\.)(youtube\\.com|youtu\\.be)$/],\n] as const satisfies readonly (readonly [Channel, ReferrerMedium, RegExp])[];\n\n/**\n * Referrer hosts that are navigation, not acquisition, when a session happens to start on the way\n * back from them: the local dev host; the payment providers a visitor is bounced through; the\n * sign-in providers whose login lives on a host of its own (Google, Apple, Microsoft, WeChat,\n * Kakao, LINE, Naver, Yahoo, Twitch, X's OAuth 1.0a endpoint); and the hosted auth services a\n * product may sit behind (Auth0, Okta, Supabase, Firebase, Clerk). A product appends its own\n * hostnames — a session that starts from an internal link after the session timeout refers to\n * them. Matched before `REFERRER_SITES`, so `nid.naver.com` and `login.yahoo.com` are not read as\n * a search. Providers whose login shares the host with their content — Facebook, X's OAuth 2.0,\n * LinkedIn, GitHub, Discord — cannot be told apart by host (referrer policies strip the path) and\n * are left as the referrers they usually are. Regular expressions over the lower-cased host.\n */\nexport const REFERRERS_NOT_A_TOUCH = [\n /^localhost(:|$)/,\n // payment\n /(^|\\.)stripe\\.com$/,\n /^pay\\.google\\.com$/,\n /(^|\\.)paypal\\.com$/,\n /(^|\\.)alipay\\.com$/,\n /(^|\\.)paddle\\.com$/,\n /(^|\\.)lemonsqueezy\\.com$/,\n // app stores\n /^apps\\.apple\\.com$/,\n /^play\\.google\\.com$/,\n // sign-in providers with a login host of their own\n /^accounts\\.google\\.com$/,\n /^appleid\\.apple\\.com$/,\n /^login\\.(microsoftonline|live)\\.com$/,\n /^open\\.weixin\\.qq\\.com$/,\n /^(kauth|accounts)\\.kakao\\.com$/,\n /^access\\.line\\.me$/,\n /^nid\\.naver\\.com$/,\n /^login\\.yahoo\\.com$/,\n /^id\\.twitch\\.tv$/,\n /^api\\.twitter\\.com$/,\n // hosted auth services\n /(^|\\.)auth0\\.com$/,\n /(^|\\.)okta\\.com$/,\n /(^|\\.)supabase\\.co$/,\n /(^|\\.)firebaseapp\\.com$/,\n /(^|\\.)clerk\\.accounts\\.dev$/,\n] as const;\n\n/** GA4's paid mediums — cpc, cpm, ppc, retargeting, paid_social, … — plus Performance Max. */\nexport const PAID_MEDIUM = /^(.*cp.*|ppc|retargeting|paid.*|pmax|performance_max)$/;\n/**\n * Meta's `{{placement}}` values, lower-cased, which an ad URL template of `utm_medium={{placement}}`\n * puts in the medium. Only an ad carries one — an organic post arrives as a referrer, with no utm\n * at all — so a medium in this list is a paid Meta click whatever the source says (a template with\n * `utm_source=meta-websitekeyinfo` was seen). Listed one by one rather than matched by prefix, so\n * that a hand-tagged `instagram_stories` post cannot be mistaken for an ad only because of how it\n * is spelled … which means a placement Meta adds later shows up as unassigned until it is added\n * here. Meta's documented values plus the ones seen in the wild (`facebook_mobile_reels`,\n * `facebook_notification`, `an`), and the literal macro for a template that did not expand it.\n */\nexport const META_PLACEMENTS = [\n 'facebook_desktop_feed',\n 'facebook_mobile_feed',\n 'facebook_mobile_reels',\n 'facebook_reels',\n 'facebook_reels_overlay',\n 'facebook_right_column',\n 'facebook_marketplace',\n 'facebook_video_feeds',\n 'facebook_stories',\n 'facebook_search',\n 'facebook_instream_video',\n 'facebook_instant_article',\n 'facebook_groups_feed',\n 'facebook_profile_feed',\n 'facebook_notification',\n 'facebook_notifications',\n 'facebook_business_explore',\n 'instagram_feed',\n 'instagram_stories',\n 'instagram_reels',\n 'instagram_reels_overlay',\n 'instagram_explore',\n 'instagram_explore_home',\n 'instagram_search',\n 'instagram_shop',\n 'instagram_profile_feed',\n 'instagram_profile_reels',\n 'instagram_igtv',\n 'messenger_inbox',\n 'messenger_stories',\n 'messenger_sponsored_messages',\n 'threads_feed',\n 'whatsapp_status',\n 'audience_network_classic',\n 'audience_network_rewarded_video',\n 'audience_network_native_banner_and_interstitial',\n 'an',\n 'others',\n /** the macro itself, when Meta did not expand it (written in a field it does not substitute, or a\n * preview click): still only ever produced by a Meta ad URL, so still a paid Meta click */\n '{{placement}}',\n] as const;\nexport const DISPLAY_MEDIUMS = ['display', 'banner', 'expandable', 'interstitial'] as const;\n/** GA4's email spellings, as a source or a medium. */\nexport const EMAIL_MEDIUMS = ['email', 'e-mail', 'e_mail', 'e mail'] as const;\n/** A medium that says email or newsletter anywhere in it: `outbound email`, `cold_email`, `newsletter`, and GA4's four. */\nexport const EMAIL_MEDIUM = /(^|[^a-z])(e[-_ ]?mail|newsletter)([^a-z]|$)/;\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. Stored on the session when it is classified, so\n * renumbering means reclassifying.\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"],"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CACA;CACA;CAGA;AACF;AACA,MAAa,kBAAkB;CAAC;CAAW;CAAU;CAAc;AAAc;;AAEjF,MAAa,gBAAgB;CAAC;CAAS;CAAU;CAAU;AAAQ;;AAEnE,MAAa,eAAe;;AAG5B,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/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
+ import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.cjs";
1
2
  import { ALL_ENVIRONMENTS, ALL_PLATFORMS, CreateFeedbackDTO, CreateLinkDTO, createFeedbackSchema, createLinkSchema, createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from "./schema/index.cjs";
2
3
  import { sendFeedback } from "./feedback/index.cjs";
3
- import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.cjs";
4
4
  import { useTrackImpression } from "./hooks/use-track-impression.cjs";
5
5
  import { VisitorProperties } from "./visitor/types.cjs";
6
6
  import { setupAnalytics } from "./setup/index.cjs";
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
+ import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.mjs";
1
2
  import { ALL_ENVIRONMENTS, ALL_PLATFORMS, CreateFeedbackDTO, CreateLinkDTO, createFeedbackSchema, createLinkSchema, createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from "./schema/index.mjs";
2
3
  import { sendFeedback } from "./feedback/index.mjs";
3
- import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.mjs";
4
4
  import { useTrackImpression } from "./hooks/use-track-impression.mjs";
5
5
  import { VisitorProperties } from "./visitor/types.mjs";
6
6
  import { setupAnalytics } from "./setup/index.mjs";
@@ -1,6 +1,6 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { Gtag } from "../track/gtag.cjs";
3
2
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
3
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
4
4
  //#region src/third-parties/google-analytics.d.ts
5
5
  declare global {
6
6
  interface Window {
@@ -1,6 +1,6 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { Gtag } from "../track/gtag.mjs";
3
2
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
3
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
4
4
  //#region src/third-parties/google-analytics.d.ts
5
5
  declare global {
6
6
  interface Window {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  import { Lintrk } from "../track/lintrk.cjs";
4
4
  //#region src/third-parties/linkedin-insight-tag.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  import { Lintrk } from "../track/lintrk.mjs";
4
4
  //#region src/third-parties/linkedin-insight-tag.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  import { FBQ, PixelId } from "../track/fbq.cjs";
4
4
  //#region src/third-parties/meta-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  import { FBQ, PixelId } from "../track/fbq.mjs";
4
4
  //#region src/third-parties/meta-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  import { UETConsent, UETQ } from "../track/uetq.cjs";
4
4
  //#region src/third-parties/microsoft-uet.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  import { UETConsent, UETQ } from "../track/uetq.mjs";
4
4
  //#region src/third-parties/microsoft-uet.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  import { OAIQ } from "../track/oaiq.cjs";
4
4
  //#region src/third-parties/openai-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  import { OAIQ } from "../track/oaiq.mjs";
4
4
  //#region src/third-parties/openai-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  import { PixelId, RDT } from "../track/rdt.cjs";
4
4
  //#region src/third-parties/reddit-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  import { PixelId, RDT } from "../track/rdt.mjs";
4
4
  //#region src/third-parties/reddit-pixel.d.ts
5
5
  declare global {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.cjs";
2
1
  import { Environment, Platform, TrackTags } from "../track/types.cjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.cjs";
3
3
  //#region src/visitor/types.d.ts
4
4
  type VisitorProperties = Record<Lowercase<string>, string | number | boolean | null>;
5
5
  interface Visitor {
@@ -1,5 +1,5 @@
1
- import { UpdateVisitorDTO } from "../schema/index.mjs";
2
1
  import { Environment, Platform, TrackTags } from "../track/types.mjs";
2
+ import { UpdateVisitorDTO } from "../schema/index.mjs";
3
3
  //#region src/visitor/types.d.ts
4
4
  type VisitorProperties = Record<Lowercase<string>, string | number | boolean | null>;
5
5
  interface Visitor {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "8.11.0",
3
+ "version": "8.13.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
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,S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AO,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"}
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}