@shware/analytics 11.5.0 → 11.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/attribution/classify.cjs +13 -6
- package/dist/attribution/classify.cjs.map +1 -1
- package/dist/attribution/classify.d.cts +1 -1
- package/dist/attribution/classify.d.cts.map +1 -1
- package/dist/attribution/classify.d.mts +1 -1
- package/dist/attribution/classify.d.mts.map +1 -1
- package/dist/attribution/classify.mjs +14 -7
- package/dist/attribution/classify.mjs.map +1 -1
- package/dist/attribution/index.cjs +1 -0
- package/dist/attribution/index.d.cts +2 -2
- package/dist/attribution/index.d.mts +2 -2
- package/dist/attribution/index.mjs +2 -2
- package/dist/attribution/vocabulary.cjs +5 -0
- package/dist/attribution/vocabulary.cjs.map +1 -1
- package/dist/attribution/vocabulary.d.cts +7 -1
- package/dist/attribution/vocabulary.d.cts.map +1 -1
- package/dist/attribution/vocabulary.d.mts +7 -1
- package/dist/attribution/vocabulary.d.mts.map +1 -1
- package/dist/attribution/vocabulary.mjs +5 -1
- package/dist/attribution/vocabulary.mjs.map +1 -1
- package/dist/native/deep-link.cjs +75 -0
- package/dist/native/deep-link.cjs.map +1 -0
- package/dist/native/deep-link.d.cts +8 -0
- package/dist/native/deep-link.d.cts.map +1 -0
- package/dist/native/deep-link.d.mts +8 -0
- package/dist/native/deep-link.d.mts.map +1 -0
- package/dist/native/deep-link.mjs +74 -0
- package/dist/native/deep-link.mjs.map +1 -0
- package/dist/native/index.cjs +2 -0
- package/dist/native/index.d.cts +2 -1
- package/dist/native/index.d.mts +2 -1
- package/dist/native/index.mjs +2 -1
- package/dist/native/setup.cjs +4 -2
- package/dist/native/setup.cjs.map +1 -1
- package/dist/native/setup.mjs +4 -2
- package/dist/native/setup.mjs.map +1 -1
- package/dist/setup/index.cjs +8 -1
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +14 -0
- package/dist/setup/index.d.cts.map +1 -1
- package/dist/setup/index.d.mts +14 -0
- package/dist/setup/index.d.mts.map +1 -1
- package/dist/setup/index.mjs +8 -1
- package/dist/setup/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +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 'telegram',\n /** Gmail's web and Android app: a link in a mail that carried no utm. */\n 'gmail',\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 th: '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, and whether the platform puts it on\n * its ad clicks only (`'ads'`) or on other links as well (`'any'`). Every key is a field this SDK\n * collects (`AdvertisingInfo`).\n *\n * The third column decides whether the id can say a click was paid when a `utm_source` names the\n * channel but no `utm_medium` says how (a Reddit ad tagged `utm_source=reddit` and nothing more).\n * `fbclid` is `'any'`: Meta decorates every outbound link with it, organic posts, profile links\n * and shares included. `twclid` and `ko_click_id` are `'any'` until it is clear they never\n * decorate an organic link.\n *\n * Only URL parameters, never the cookies the tags keep beside them (`_fbc`, `_gcl_aw`, … — every\n * underscore key of `AdvertisingInfo`): a click cookie lives up to 90 days after the click, so\n * counting it named every later visit — typed in, from search, from an email — a new ad click.\n */\nexport const CLICK_ID_CHANNELS = [\n ['fbclid', 'meta', 'any'],\n ['gclid', 'google', 'ads'],\n ['gbraid', 'google', 'ads'],\n ['wbraid', 'google', 'ads'],\n ['gad_source', 'google', 'ads'],\n ['gad_campaignid', 'google', 'ads'],\n ['dclid', 'dv360', 'ads'],\n ['msclkid', 'microsoft', 'ads'],\n ['ttclid', 'tiktok', 'ads'],\n ['rdt_cid', 'reddit', 'ads'],\n ['li_fat_id', 'linkedin', 'ads'],\n ['ScCid', 'snapchat', 'ads'],\n ['twclid', 'x', 'any'],\n ['ko_click_id', 'kakao', 'any'],\n ['yclid', 'yandex', 'ads'],\n ['oppref', 'chatgpt', 'ads'],\n ['epik', 'pinterest', 'ads'],\n] as const satisfies readonly (readonly [keyof AdvertisingInfo, Channel, 'ads' | 'any'])[];\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' | 'email';\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 // Before google, whose pattern it would match.\n ['gmail', 'email', /^mail\\.google\\.com$/],\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 ['telegram', 'social', /^(t\\.me|telegram\\.me|(web\\.)?telegram\\.org)$/],\n ['youtube', 'video', /(^|\\.)(youtube\\.com|youtu\\.be)$/],\n] as const satisfies readonly (readonly [Channel, ReferrerMedium, RegExp])[];\n\n/**\n * The site an Android app's referrer stands for. A link opened from an app on Android arrives with\n * `android-app://<package>/` as its referrer rather than the site's URL; the apps below are read as\n * their sites, so the Google app is a Google search and the LinkedIn app is LinkedIn. A package\n * not listed is kept as the referring host, as GA4 shows it; Meta's apps send their mobile host\n * (`android-app://m.facebook.com`), which needs no entry.\n */\nexport const ANDROID_APP_HOSTS: Readonly<Record<string, string>> = {\n 'com.google.android.googlequicksearchbox': 'www.google.com',\n 'com.google.android.gm': 'mail.google.com',\n 'com.google.android.youtube': 'www.youtube.com',\n 'com.facebook.katana': 'www.facebook.com',\n 'com.instagram.android': 'www.instagram.com',\n 'com.linkedin.android': 'www.linkedin.com',\n 'com.reddit.frontpage': 'www.reddit.com',\n 'com.twitter.android': 'x.com',\n 'com.zhiliaoapp.musically': 'www.tiktok.com',\n 'com.ss.android.ugc.trill': 'www.tiktok.com',\n 'com.pinterest': 'www.pinterest.com',\n 'com.snapchat.android': 'www.snapchat.com',\n 'org.telegram.messenger': 't.me',\n};\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 organic social (or unassigned,\n * under a source that is no social site) until it is added here. Meta's documented values plus the\n * ones seen in the wild (`facebook_mobile_reels`, `facebook_notification`, `an`), and the literal\n * macro for a template that did not expand it.\n *\n * Accepted for the ads already running with that template; new ads should rather send\n * `utm_medium=cpc` and the placement in a `placement` parameter of its own (collected as the\n * `placement` tag): GA4 matches its paid rule on the medium alone, and files a placement medium\n * under Organic Social.\n */\nexport const META_PLACEMENTS = [\n 'facebook_feed',\n 'facebook_instream',\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 'threads_stream',\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 * (a campaign rule whose touch is organic by its own tag ranking as a referrer, see `classifyTouch`).\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 /**\n * utm, click id, ad landing page: someone tagged that link (in that order within a session) —\n * unless the tag itself calls the touch organic, a referral or email, which then ranks as `referrer`\n */\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":";;;;;;;;AAUA,MAAa,iBAAiB;;AAE9B,MAAa,YAAY;;AAEzB,MAAa,iBAAiB;;AAG9B,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A,MAAa,wBAAwB;CACnC;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAa,cAAc;;;;;;;;;;;;;;;;;AAiB3B,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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;;;;;;;;;;;;;AAe9E,MAAa,iBAAiB;;;;;CAK5B,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
|
+
{"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 'telegram',\n /** Gmail's web and Android app: a link in a mail that carried no utm. */\n 'gmail',\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 /** GA4's SMS: `sms` as the source or the medium */\n 'sms',\n /** GA4's Mobile Push Notifications: a medium ending in `push` or naming mobile or a notification, or `firebase` as the source */\n 'mobile_push',\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 th: '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, and whether the platform puts it on\n * its ad clicks only (`'ads'`) or on other links as well (`'any'`). Every key is a field this SDK\n * collects (`AdvertisingInfo`).\n *\n * The third column decides whether the id can say a click was paid when a `utm_source` names the\n * channel but no `utm_medium` says how (a Reddit ad tagged `utm_source=reddit` and nothing more).\n * `fbclid` is `'any'`: Meta decorates every outbound link with it, organic posts, profile links\n * and shares included. `twclid` and `ko_click_id` are `'any'` until it is clear they never\n * decorate an organic link.\n *\n * Only URL parameters, never the cookies the tags keep beside them (`_fbc`, `_gcl_aw`, … — every\n * underscore key of `AdvertisingInfo`): a click cookie lives up to 90 days after the click, so\n * counting it named every later visit — typed in, from search, from an email — a new ad click.\n */\nexport const CLICK_ID_CHANNELS = [\n ['fbclid', 'meta', 'any'],\n ['gclid', 'google', 'ads'],\n ['gbraid', 'google', 'ads'],\n ['wbraid', 'google', 'ads'],\n ['gad_source', 'google', 'ads'],\n ['gad_campaignid', 'google', 'ads'],\n ['dclid', 'dv360', 'ads'],\n ['msclkid', 'microsoft', 'ads'],\n ['ttclid', 'tiktok', 'ads'],\n ['rdt_cid', 'reddit', 'ads'],\n ['li_fat_id', 'linkedin', 'ads'],\n ['ScCid', 'snapchat', 'ads'],\n ['twclid', 'x', 'any'],\n ['ko_click_id', 'kakao', 'any'],\n ['yclid', 'yandex', 'ads'],\n ['oppref', 'chatgpt', 'ads'],\n ['epik', 'pinterest', 'ads'],\n] as const satisfies readonly (readonly [keyof AdvertisingInfo, Channel, 'ads' | 'any'])[];\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' | 'email';\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 // Before google, whose pattern it would match.\n ['gmail', 'email', /^mail\\.google\\.com$/],\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 ['telegram', 'social', /^(t\\.me|telegram\\.me|(web\\.)?telegram\\.org)$/],\n ['youtube', 'video', /(^|\\.)(youtube\\.com|youtu\\.be)$/],\n] as const satisfies readonly (readonly [Channel, ReferrerMedium, RegExp])[];\n\n/**\n * The site an Android app's referrer stands for. A link opened from an app on Android arrives with\n * `android-app://<package>/` as its referrer rather than the site's URL; the apps below are read as\n * their sites, so the Google app is a Google search and the LinkedIn app is LinkedIn. A package\n * not listed is kept as the referring host, as GA4 shows it; Meta's apps send their mobile host\n * (`android-app://m.facebook.com`), which needs no entry.\n */\nexport const ANDROID_APP_HOSTS: Readonly<Record<string, string>> = {\n 'com.google.android.googlequicksearchbox': 'www.google.com',\n 'com.google.android.gm': 'mail.google.com',\n 'com.google.android.youtube': 'www.youtube.com',\n 'com.facebook.katana': 'www.facebook.com',\n 'com.instagram.android': 'www.instagram.com',\n 'com.linkedin.android': 'www.linkedin.com',\n 'com.reddit.frontpage': 'www.reddit.com',\n 'com.twitter.android': 'x.com',\n 'com.zhiliaoapp.musically': 'www.tiktok.com',\n 'com.ss.android.ugc.trill': 'www.tiktok.com',\n 'com.pinterest': 'www.pinterest.com',\n 'com.snapchat.android': 'www.snapchat.com',\n 'org.telegram.messenger': 't.me',\n};\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 organic social (or unassigned,\n * under a source that is no social site) until it is added here. Meta's documented values plus the\n * ones seen in the wild (`facebook_mobile_reels`, `facebook_notification`, `an`), and the literal\n * macro for a template that did not expand it.\n *\n * Accepted for the ads already running with that template; new ads should rather send\n * `utm_medium=cpc` and the placement in a `placement` parameter of its own (collected as the\n * `placement` tag): GA4 matches its paid rule on the medium alone, and files a placement medium\n * under Organic Social.\n */\nexport const META_PLACEMENTS = [\n 'facebook_feed',\n 'facebook_instream',\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 'threads_stream',\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/** GA4's Mobile Push Notifications medium: ending in `push`, or containing `mobile` or `notification`. */\nexport const PUSH_MEDIUM = /(push$|mobile|notification)/;\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 * (a campaign rule whose touch is organic by its own tag ranking as a referrer, see `classifyTouch`).\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 /**\n * utm, click id, ad landing page: someone tagged that link (in that order within a session) —\n * unless the tag itself calls the touch organic, a referral or email, which then ranks as `referrer`\n */\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":";;;;;;;;AAUA,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;CACA;CAEA;CAIA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAKA;AACF;;AAKA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CAEA;CACA;AACF;;AAKA,MAAa,iBAAiB;CAC5B,IA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A;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;AACF;AACA,MAAa,kBAAkB;CAAC;CAAW;CAAU;CAAc;AAAc;;AAEjF,MAAa,gBAAgB;CAAC;CAAS;CAAU;CAAU;AAAQ;;AAEnE,MAAa,cAAc;;AAE3B,MAAa,eAAe;;AAG5B,MAAa,gBAAgB,CAAC,WAAW,UAAU;;;;;;;;AAUnD,MAAa,uBAAuB;CAAC;CAAU;CAAc;CAAS;AAAQ;;;;;;;;;;;;;AAe9E,MAAa,iBAAiB;;;;;CAK5B,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,75 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react_native = require("react-native");
|
|
3
|
+
let react_native_url_polyfill = require("react-native-url-polyfill");
|
|
4
|
+
//#region src/native/deep-link.ts
|
|
5
|
+
/**
|
|
6
|
+
* The link that opened the app for this visit, the app's landing page: `getTags` merges its URL
|
|
7
|
+
* (as `page_location`) and utm into every event's tags, so the session it starts is
|
|
8
|
+
* classified as a web page's URL would be. A universal link or an app link from an email or an ad
|
|
9
|
+
* opens the app rather than the site, and without this every one of those sessions was direct.
|
|
10
|
+
*
|
|
11
|
+
* The visit lasts from the open to the app going to the background, so every event in between
|
|
12
|
+
* carries the link, as every event of a web page carries that page's query; the next open, with a
|
|
13
|
+
* link or without, starts from nothing. Only the event that starts a session gets it classified:
|
|
14
|
+
* a link tapped while the session is still running joins it, as GA4 keeps one session across a
|
|
15
|
+
* change of campaign.
|
|
16
|
+
*
|
|
17
|
+
* Read from React Native's `Linking`: the URL that launched the process, and each one that brings
|
|
18
|
+
* the running app to the front. Pass it to `setupAnalytics({ deepLink })`, which starts the
|
|
19
|
+
* listening; nothing happens at import.
|
|
20
|
+
*/
|
|
21
|
+
let openUrl;
|
|
22
|
+
/**
|
|
23
|
+
* The parameters a deep link carries: the utm its sender tagged it with. An ad platform's click id
|
|
24
|
+
* rides on the web landing page, not on a link into the app.
|
|
25
|
+
*/
|
|
26
|
+
const UTM_KEYS = [
|
|
27
|
+
"utm_source",
|
|
28
|
+
"utm_medium",
|
|
29
|
+
"utm_campaign",
|
|
30
|
+
"utm_term",
|
|
31
|
+
"utm_content",
|
|
32
|
+
"utm_id",
|
|
33
|
+
"utm_source_platform",
|
|
34
|
+
"utm_creative_format",
|
|
35
|
+
"utm_marketing_tactic"
|
|
36
|
+
];
|
|
37
|
+
let initialUrlPromise;
|
|
38
|
+
let listening = false;
|
|
39
|
+
/** The URL that launched the process, read once; a link that arrived since has the last word. */
|
|
40
|
+
function resolveInitialUrl() {
|
|
41
|
+
initialUrlPromise ??= react_native.Linking.getInitialURL().then((url) => {
|
|
42
|
+
if (url && openUrl === void 0) openUrl = url;
|
|
43
|
+
}, () => void 0);
|
|
44
|
+
return initialUrlPromise;
|
|
45
|
+
}
|
|
46
|
+
const deepLink = {
|
|
47
|
+
listen() {
|
|
48
|
+
if (listening) return;
|
|
49
|
+
listening = true;
|
|
50
|
+
react_native.Linking.addEventListener("url", ({ url }) => deepLink.open(url));
|
|
51
|
+
react_native.AppState.addEventListener("change", (state) => {
|
|
52
|
+
if (state === "background") openUrl = void 0;
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
/** Waits for the launch URL, so the first event of a launch has it. */
|
|
56
|
+
async getTags() {
|
|
57
|
+
await resolveInitialUrl();
|
|
58
|
+
if (!openUrl) return {};
|
|
59
|
+
const at = openUrl.indexOf("?");
|
|
60
|
+
const params = new react_native_url_polyfill.URLSearchParams(at === -1 ? "" : openUrl.slice(at + 1).split("#")[0]);
|
|
61
|
+
const tags = { page_location: openUrl };
|
|
62
|
+
for (const key of UTM_KEYS) {
|
|
63
|
+
const value = params.get(key);
|
|
64
|
+
if (value !== null) tags[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return tags;
|
|
67
|
+
},
|
|
68
|
+
open(url) {
|
|
69
|
+
openUrl = url || void 0;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.deepLink = deepLink;
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=deep-link.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-link.cjs","names":["Linking","URLSearchParams"],"sources":["../../src/native/deep-link.ts"],"sourcesContent":["import { AppState, Linking } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport type { DeepLink } from '../setup/index';\nimport type { TrackTags, UTMParams } from '../track/types';\n\n/**\n * The link that opened the app for this visit, the app's landing page: `getTags` merges its URL\n * (as `page_location`) and utm into every event's tags, so the session it starts is\n * classified as a web page's URL would be. A universal link or an app link from an email or an ad\n * opens the app rather than the site, and without this every one of those sessions was direct.\n *\n * The visit lasts from the open to the app going to the background, so every event in between\n * carries the link, as every event of a web page carries that page's query; the next open, with a\n * link or without, starts from nothing. Only the event that starts a session gets it classified:\n * a link tapped while the session is still running joins it, as GA4 keeps one session across a\n * change of campaign.\n *\n * Read from React Native's `Linking`: the URL that launched the process, and each one that brings\n * the running app to the front. Pass it to `setupAnalytics({ deepLink })`, which starts the\n * listening; nothing happens at import.\n */\nlet openUrl: string | undefined;\n\n/**\n * The parameters a deep link carries: the utm its sender tagged it with. An ad platform's click id\n * rides on the web landing page, not on a link into the app.\n */\nconst UTM_KEYS = [\n 'utm_source',\n 'utm_medium',\n 'utm_campaign',\n 'utm_term',\n 'utm_content',\n 'utm_id',\n 'utm_source_platform',\n 'utm_creative_format',\n 'utm_marketing_tactic',\n] as const satisfies readonly (keyof UTMParams)[];\nlet initialUrlPromise: Promise<void> | undefined;\nlet listening = false;\n\n/** The URL that launched the process, read once; a link that arrived since has the last word. */\nfunction resolveInitialUrl(): Promise<void> {\n initialUrlPromise ??= Linking.getInitialURL().then(\n (url) => {\n if (url && openUrl === undefined) openUrl = url;\n },\n () => undefined\n );\n return initialUrlPromise;\n}\n\nexport const deepLink: DeepLink & {\n /** The link this visit opened with, for an entry `Linking` does not see, such as a push notification. */\n open: (url: string | null | undefined) => void;\n} = {\n listen() {\n if (listening) return;\n listening = true;\n Linking.addEventListener('url', ({ url }) => deepLink.open(url));\n // `background`, not `inactive`: iOS goes inactive for a system sheet or the control center,\n // with the visit still on.\n AppState.addEventListener('change', (state) => {\n if (state === 'background') openUrl = undefined;\n });\n },\n /** Waits for the launch URL, so the first event of a launch has it. */\n async getTags(): Promise<TrackTags> {\n await resolveInitialUrl();\n if (!openUrl) return {};\n const at = openUrl.indexOf('?');\n const params = new URLSearchParams(at === -1 ? '' : openUrl.slice(at + 1).split('#')[0]);\n const tags: TrackTags = { page_location: openUrl };\n for (const key of UTM_KEYS) {\n const value = params.get(key);\n if (value !== null) tags[key] = value;\n }\n return tags;\n },\n open(url) {\n openUrl = url || undefined;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,IAAI;;;;;AAMJ,MAAM,WAAW;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAI;AACJ,IAAI,YAAY;;AAGhB,SAAS,oBAAmC;CAC1C,sBAAsBA,aAAAA,QAAQ,cAAc,CAAC,CAAC,MAC3C,QAAQ;EACP,IAAI,OAAO,YAAY,KAAA,GAAW,UAAU;CAC9C,SACM,KAAA,CACR;CACA,OAAO;AACT;AAEA,MAAa,WAGT;CACF,SAAS;EACP,IAAI,WAAW;EACf,YAAY;EACZ,aAAA,QAAQ,iBAAiB,QAAQ,EAAE,UAAU,SAAS,KAAK,GAAG,CAAC;EAG/D,aAAA,SAAS,iBAAiB,WAAW,UAAU;GAC7C,IAAI,UAAU,cAAc,UAAU,KAAA;EACxC,CAAC;CACH;;CAEA,MAAM,UAA8B;EAClC,MAAM,kBAAkB;EACxB,IAAI,CAAC,SAAS,OAAO,CAAC;EACtB,MAAM,KAAK,QAAQ,QAAQ,GAAG;EAC9B,MAAM,SAAS,IAAIC,0BAAAA,gBAAgB,OAAO,KAAK,KAAK,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;EACvF,MAAM,OAAkB,EAAE,eAAe,QAAQ;EACjD,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,QAAQ,OAAO,IAAI,GAAG;GAC5B,IAAI,UAAU,MAAM,KAAK,OAAO;EAClC;EACA,OAAO;CACT;CACA,KAAK,KAAK;EACR,UAAU,OAAO,KAAA;CACnB;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DeepLink } from "../setup/index.cjs";
|
|
2
|
+
//#region src/native/deep-link.d.ts
|
|
3
|
+
export declare const deepLink: DeepLink & {
|
|
4
|
+
/** The link this visit opened with, for an entry `Linking` does not see, such as a push notification. */
|
|
5
|
+
open: (url: string | null | undefined) => void;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=deep-link.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-link.d.cts","names":[],"sources":["../../src/native/deep-link.ts"],"mappings":";;qBAoDa,UAAU;;EAErB,OAAO"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DeepLink } from "../setup/index.mjs";
|
|
2
|
+
//#region src/native/deep-link.d.ts
|
|
3
|
+
export declare const deepLink: DeepLink & {
|
|
4
|
+
/** The link this visit opened with, for an entry `Linking` does not see, such as a push notification. */
|
|
5
|
+
open: (url: string | null | undefined) => void;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=deep-link.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-link.d.mts","names":[],"sources":["../../src/native/deep-link.ts"],"mappings":";;qBAoDa,UAAU;;EAErB,OAAO"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AppState, Linking } from "react-native";
|
|
2
|
+
import { URLSearchParams } from "react-native-url-polyfill";
|
|
3
|
+
//#region src/native/deep-link.ts
|
|
4
|
+
/**
|
|
5
|
+
* The link that opened the app for this visit, the app's landing page: `getTags` merges its URL
|
|
6
|
+
* (as `page_location`) and utm into every event's tags, so the session it starts is
|
|
7
|
+
* classified as a web page's URL would be. A universal link or an app link from an email or an ad
|
|
8
|
+
* opens the app rather than the site, and without this every one of those sessions was direct.
|
|
9
|
+
*
|
|
10
|
+
* The visit lasts from the open to the app going to the background, so every event in between
|
|
11
|
+
* carries the link, as every event of a web page carries that page's query; the next open, with a
|
|
12
|
+
* link or without, starts from nothing. Only the event that starts a session gets it classified:
|
|
13
|
+
* a link tapped while the session is still running joins it, as GA4 keeps one session across a
|
|
14
|
+
* change of campaign.
|
|
15
|
+
*
|
|
16
|
+
* Read from React Native's `Linking`: the URL that launched the process, and each one that brings
|
|
17
|
+
* the running app to the front. Pass it to `setupAnalytics({ deepLink })`, which starts the
|
|
18
|
+
* listening; nothing happens at import.
|
|
19
|
+
*/
|
|
20
|
+
let openUrl;
|
|
21
|
+
/**
|
|
22
|
+
* The parameters a deep link carries: the utm its sender tagged it with. An ad platform's click id
|
|
23
|
+
* rides on the web landing page, not on a link into the app.
|
|
24
|
+
*/
|
|
25
|
+
const UTM_KEYS = [
|
|
26
|
+
"utm_source",
|
|
27
|
+
"utm_medium",
|
|
28
|
+
"utm_campaign",
|
|
29
|
+
"utm_term",
|
|
30
|
+
"utm_content",
|
|
31
|
+
"utm_id",
|
|
32
|
+
"utm_source_platform",
|
|
33
|
+
"utm_creative_format",
|
|
34
|
+
"utm_marketing_tactic"
|
|
35
|
+
];
|
|
36
|
+
let initialUrlPromise;
|
|
37
|
+
let listening = false;
|
|
38
|
+
/** The URL that launched the process, read once; a link that arrived since has the last word. */
|
|
39
|
+
function resolveInitialUrl() {
|
|
40
|
+
initialUrlPromise ??= Linking.getInitialURL().then((url) => {
|
|
41
|
+
if (url && openUrl === void 0) openUrl = url;
|
|
42
|
+
}, () => void 0);
|
|
43
|
+
return initialUrlPromise;
|
|
44
|
+
}
|
|
45
|
+
const deepLink = {
|
|
46
|
+
listen() {
|
|
47
|
+
if (listening) return;
|
|
48
|
+
listening = true;
|
|
49
|
+
Linking.addEventListener("url", ({ url }) => deepLink.open(url));
|
|
50
|
+
AppState.addEventListener("change", (state) => {
|
|
51
|
+
if (state === "background") openUrl = void 0;
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
/** Waits for the launch URL, so the first event of a launch has it. */
|
|
55
|
+
async getTags() {
|
|
56
|
+
await resolveInitialUrl();
|
|
57
|
+
if (!openUrl) return {};
|
|
58
|
+
const at = openUrl.indexOf("?");
|
|
59
|
+
const params = new URLSearchParams(at === -1 ? "" : openUrl.slice(at + 1).split("#")[0]);
|
|
60
|
+
const tags = { page_location: openUrl };
|
|
61
|
+
for (const key of UTM_KEYS) {
|
|
62
|
+
const value = params.get(key);
|
|
63
|
+
if (value !== null) tags[key] = value;
|
|
64
|
+
}
|
|
65
|
+
return tags;
|
|
66
|
+
},
|
|
67
|
+
open(url) {
|
|
68
|
+
openUrl = url || void 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { deepLink };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=deep-link.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-link.mjs","names":[],"sources":["../../src/native/deep-link.ts"],"sourcesContent":["import { AppState, Linking } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport type { DeepLink } from '../setup/index';\nimport type { TrackTags, UTMParams } from '../track/types';\n\n/**\n * The link that opened the app for this visit, the app's landing page: `getTags` merges its URL\n * (as `page_location`) and utm into every event's tags, so the session it starts is\n * classified as a web page's URL would be. A universal link or an app link from an email or an ad\n * opens the app rather than the site, and without this every one of those sessions was direct.\n *\n * The visit lasts from the open to the app going to the background, so every event in between\n * carries the link, as every event of a web page carries that page's query; the next open, with a\n * link or without, starts from nothing. Only the event that starts a session gets it classified:\n * a link tapped while the session is still running joins it, as GA4 keeps one session across a\n * change of campaign.\n *\n * Read from React Native's `Linking`: the URL that launched the process, and each one that brings\n * the running app to the front. Pass it to `setupAnalytics({ deepLink })`, which starts the\n * listening; nothing happens at import.\n */\nlet openUrl: string | undefined;\n\n/**\n * The parameters a deep link carries: the utm its sender tagged it with. An ad platform's click id\n * rides on the web landing page, not on a link into the app.\n */\nconst UTM_KEYS = [\n 'utm_source',\n 'utm_medium',\n 'utm_campaign',\n 'utm_term',\n 'utm_content',\n 'utm_id',\n 'utm_source_platform',\n 'utm_creative_format',\n 'utm_marketing_tactic',\n] as const satisfies readonly (keyof UTMParams)[];\nlet initialUrlPromise: Promise<void> | undefined;\nlet listening = false;\n\n/** The URL that launched the process, read once; a link that arrived since has the last word. */\nfunction resolveInitialUrl(): Promise<void> {\n initialUrlPromise ??= Linking.getInitialURL().then(\n (url) => {\n if (url && openUrl === undefined) openUrl = url;\n },\n () => undefined\n );\n return initialUrlPromise;\n}\n\nexport const deepLink: DeepLink & {\n /** The link this visit opened with, for an entry `Linking` does not see, such as a push notification. */\n open: (url: string | null | undefined) => void;\n} = {\n listen() {\n if (listening) return;\n listening = true;\n Linking.addEventListener('url', ({ url }) => deepLink.open(url));\n // `background`, not `inactive`: iOS goes inactive for a system sheet or the control center,\n // with the visit still on.\n AppState.addEventListener('change', (state) => {\n if (state === 'background') openUrl = undefined;\n });\n },\n /** Waits for the launch URL, so the first event of a launch has it. */\n async getTags(): Promise<TrackTags> {\n await resolveInitialUrl();\n if (!openUrl) return {};\n const at = openUrl.indexOf('?');\n const params = new URLSearchParams(at === -1 ? '' : openUrl.slice(at + 1).split('#')[0]);\n const tags: TrackTags = { page_location: openUrl };\n for (const key of UTM_KEYS) {\n const value = params.get(key);\n if (value !== null) tags[key] = value;\n }\n return tags;\n },\n open(url) {\n openUrl = url || undefined;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,IAAI;;;;;AAMJ,MAAM,WAAW;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAI;AACJ,IAAI,YAAY;;AAGhB,SAAS,oBAAmC;CAC1C,sBAAsB,QAAQ,cAAc,CAAC,CAAC,MAC3C,QAAQ;EACP,IAAI,OAAO,YAAY,KAAA,GAAW,UAAU;CAC9C,SACM,KAAA,CACR;CACA,OAAO;AACT;AAEA,MAAa,WAGT;CACF,SAAS;EACP,IAAI,WAAW;EACf,YAAY;EACZ,QAAQ,iBAAiB,QAAQ,EAAE,UAAU,SAAS,KAAK,GAAG,CAAC;EAG/D,SAAS,iBAAiB,WAAW,UAAU;GAC7C,IAAI,UAAU,cAAc,UAAU,KAAA;EACxC,CAAC;CACH;;CAEA,MAAM,UAA8B;EAClC,MAAM,kBAAkB;EACxB,IAAI,CAAC,SAAS,OAAO,CAAC;EACtB,MAAM,KAAK,QAAQ,QAAQ,GAAG;EAC9B,MAAM,SAAS,IAAI,gBAAgB,OAAO,KAAK,KAAK,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;EACvF,MAAM,OAAkB,EAAE,eAAe,QAAQ;EACjD,KAAK,MAAM,OAAO,UAAU;GAC1B,MAAM,QAAQ,OAAO,IAAI,GAAG;GAC5B,IAAI,UAAU,MAAM,KAAK,OAAO;EAClC;EACA,OAAO;CACT;CACA,KAAK,KAAK;EACR,UAAU,OAAO,KAAA;CACnB;AACF"}
|
package/dist/native/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_hooks_use_app_analytics = require("../hooks/use-app-analytics.cjs");
|
|
3
|
+
const require_native_deep_link = require("./deep-link.cjs");
|
|
3
4
|
const require_native_fingerprint = require("./fingerprint.cjs");
|
|
4
5
|
const require_native_setup = require("./setup.cjs");
|
|
6
|
+
exports.deepLink = require_native_deep_link.deepLink;
|
|
5
7
|
exports.getDeterministicFingerprint = require_native_fingerprint.getDeterministicFingerprint;
|
|
6
8
|
exports.getDeviceId = require_native_setup.getDeviceId;
|
|
7
9
|
exports.getDeviceType = require_native_setup.getDeviceType;
|
package/dist/native/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useAppAnalytics } from "../hooks/use-app-analytics.cjs";
|
|
2
|
+
import { deepLink } from "./deep-link.cjs";
|
|
2
3
|
import { DeterministicFingerprint, ProbabilisticFingerprint, getDeterministicFingerprint, getProbabilisticFingerprint } from "./fingerprint.cjs";
|
|
3
4
|
import { getDeviceId, getDeviceType, getTags, storage } from "./setup.cjs";
|
|
4
|
-
export { type DeterministicFingerprint, type ProbabilisticFingerprint, getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
|
5
|
+
export { type DeterministicFingerprint, type ProbabilisticFingerprint, deepLink, getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
package/dist/native/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useAppAnalytics } from "../hooks/use-app-analytics.mjs";
|
|
2
|
+
import { deepLink } from "./deep-link.mjs";
|
|
2
3
|
import { DeterministicFingerprint, ProbabilisticFingerprint, getDeterministicFingerprint, getProbabilisticFingerprint } from "./fingerprint.mjs";
|
|
3
4
|
import { getDeviceId, getDeviceType, getTags, storage } from "./setup.mjs";
|
|
4
|
-
export { type DeterministicFingerprint, type ProbabilisticFingerprint, getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
|
5
|
+
export { type DeterministicFingerprint, type ProbabilisticFingerprint, deepLink, getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
package/dist/native/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useAppAnalytics } from "../hooks/use-app-analytics.mjs";
|
|
2
|
+
import { deepLink } from "./deep-link.mjs";
|
|
2
3
|
import { getDeterministicFingerprint, getProbabilisticFingerprint } from "./fingerprint.mjs";
|
|
3
4
|
import { getDeviceId, getDeviceType, getTags, storage } from "./setup.mjs";
|
|
4
|
-
export { getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
|
5
|
+
export { deepLink, getDeterministicFingerprint, getDeviceId, getDeviceType, getProbabilisticFingerprint, getTags, storage, useAppAnalytics };
|
package/dist/native/setup.cjs
CHANGED
|
@@ -2,13 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_setup_index = require("../setup/index.cjs");
|
|
3
3
|
const require_constants_storage = require("../constants/storage.cjs");
|
|
4
4
|
let react_native = require("react-native");
|
|
5
|
+
let react_native_url_polyfill = require("react-native-url-polyfill");
|
|
5
6
|
let expo_application = require("expo-application");
|
|
6
7
|
let expo_device = require("expo-device");
|
|
7
8
|
let expo_localization = require("expo-localization");
|
|
8
9
|
require("expo-sqlite/localStorage/install");
|
|
9
10
|
let expo_crypto = require("expo-crypto");
|
|
10
11
|
let expo_tracking_transparency = require("expo-tracking-transparency");
|
|
11
|
-
let react_native_url_polyfill = require("react-native-url-polyfill");
|
|
12
12
|
//#region src/native/setup.ts
|
|
13
13
|
const map = /* @__PURE__ */ new Map();
|
|
14
14
|
const storage = {
|
|
@@ -105,6 +105,7 @@ async function getTags() {
|
|
|
105
105
|
const install_referrer = await getInstallReferrer();
|
|
106
106
|
if (install_referrer && installLaunch === void 0) installLaunch = claimInstallReferrer();
|
|
107
107
|
const params = new react_native_url_polyfill.URLSearchParams(installLaunch ? install_referrer : void 0);
|
|
108
|
+
const opening = await require_setup_index.config.deepLink?.getTags();
|
|
108
109
|
const tags = {
|
|
109
110
|
os: `${expo_device.osName} ${expo_device.osVersion}`,
|
|
110
111
|
os_name: expo_device.osName ?? void 0,
|
|
@@ -131,7 +132,8 @@ async function getTags() {
|
|
|
131
132
|
utm_id: params.get("utm_id") ?? void 0,
|
|
132
133
|
utm_source_platform: params.get("utm_source_platform") ?? void 0,
|
|
133
134
|
utm_creative_format: params.get("utm_creative_format") ?? void 0,
|
|
134
|
-
utm_marketing_tactic: params.get("utm_marketing_tactic") ?? void 0
|
|
135
|
+
utm_marketing_tactic: params.get("utm_marketing_tactic") ?? void 0,
|
|
136
|
+
...opening
|
|
135
137
|
};
|
|
136
138
|
require_setup_index.cache.tags = tags;
|
|
137
139
|
return tags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.cjs","names":["Platform","getInstallReferrerAsync","getIosIdForVendorAsync","getAndroidId","randomUUID","deviceType","DeviceType","config","keys","Dimensions","URLSearchParams","osName","osVersion","modelName","manufacturer","modelId","PixelRatio","getLocales","getCalendars","getAdvertisingId"],"sources":["../../src/native/setup.ts"],"sourcesContent":["import 'expo-sqlite/localStorage/install';\nimport { getAndroidId, getInstallReferrerAsync, getIosIdForVendorAsync } from 'expo-application';\nimport { randomUUID } from 'expo-crypto';\nimport {\n DeviceType,\n deviceType,\n manufacturer,\n modelId,\n modelName,\n osName,\n osVersion,\n} from 'expo-device';\nimport { getCalendars, getLocales } from 'expo-localization';\nimport { getAdvertisingId } from 'expo-tracking-transparency';\nimport { Dimensions, PixelRatio, Platform } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport { keys } from '../constants/storage';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n\n/**\n * `getTags` runs once per event now, and both of these reach for a native module. Neither answer\n * can change while the app is running, so each is resolved once and the promise is reused. A\n * failed lookup is not cached, so the next event tries again.\n */\nlet deviceIdPromise: Promise<string> | undefined;\nlet installReferrerPromise: Promise<string | undefined> | undefined;\n\nexport function getDeviceId(): Promise<string> {\n deviceIdPromise ??= resolveDeviceId().catch((error: unknown) => {\n deviceIdPromise = undefined;\n throw error;\n });\n return deviceIdPromise;\n}\n\nfunction getInstallReferrer(): Promise<string | undefined> {\n if (Platform.OS !== 'android') return Promise.resolve(undefined);\n installReferrerPromise ??= getInstallReferrerAsync().catch((error: unknown) => {\n installReferrerPromise = undefined;\n throw error;\n });\n return installReferrerPromise;\n}\n\nasync function resolveDeviceId(): Promise<string> {\n let deviceId: string | null = null;\n if (Platform.OS === 'ios') {\n deviceId = await getIosIdForVendorAsync();\n } else if (Platform.OS === 'android') {\n deviceId = getAndroidId();\n }\n if (!deviceId) {\n deviceId = localStorage.getItem('device_id');\n if (!deviceId) {\n deviceId = randomUUID();\n localStorage.setItem('device_id', deviceId);\n }\n }\n return deviceId;\n}\n\nexport function getDeviceType(): string | undefined {\n switch (deviceType) {\n case DeviceType.PHONE:\n return 'mobile';\n case DeviceType.TABLET:\n return 'tablet';\n case DeviceType.DESKTOP:\n return 'desktop';\n case DeviceType.TV:\n return 'smarttv';\n default:\n return undefined;\n }\n}\n\n/**\n * The install referrer's utm belongs to one launch: the first one that has the referrer in hand\n * — normally the install launch, since `first_open` is the first event the app tracks and\n * tracking it builds the first tags. That launch claims the referrer by writing a marker of its\n * own, and holds the claim for the rest of the process, so every event of the launch and the\n * visitor created from it carry the utm; every later launch finds the marker and sends the raw\n * `install_referrer` alone. Cleared storage and a reinstall lose the marker and claim again,\n * exactly as they make `first_open` fire again.\n *\n * Claimed only once a referrer has actually been resolved. The Install Referrer API needs the\n * Play Store service, which is at its least available right after an install; a launch that\n * could not reach it must not spend the claim on nothing, because the referrer stays readable\n * for 90 days and a later launch can still take it — late attribution, rather than none. iOS\n * has no referrer and so never claims.\n *\n * A marker of its own rather than `first_open_time`, so that nothing here depends on when the\n * hook writes that one relative to the first `getTags`. The storage read waits for that call:\n * `setupAnalytics` and this module's evaluation can run where no storage exists.\n */\nlet installLaunch: boolean | undefined;\n\nfunction claimInstallReferrer(): boolean {\n if (config.storage.getItem(keys.install_referrer_claim_time)) return false;\n config.storage.setItem(keys.install_referrer_claim_time, new Date().toISOString());\n return true;\n}\n\nexport async function getTags(): Promise<TrackTags> {\n const screen = Dimensions.get('screen');\n const screen_width = Math.floor(screen.width);\n const screen_height = Math.floor(screen.height);\n\n // The install referrer never changes, and it used to be spread into `utm_*` on every launch —\n // so every session of an Android install reported the install campaign as its own acquisition\n // for as long as the app stayed installed, and a report reading a session's tags could not tell\n // the install from the thousandth open. The campaign is the install's touch, not every\n // session's.\n const install_referrer = await getInstallReferrer();\n if (install_referrer && installLaunch === undefined) installLaunch = claimInstallReferrer();\n const params = new URLSearchParams(installLaunch ? install_referrer : undefined);\n\n const tags: TrackTags = {\n os: `${osName} ${osVersion}`,\n os_name: osName ?? undefined,\n os_version: osVersion ?? undefined,\n device: modelName ?? undefined,\n device_id: await getDeviceId(),\n device_type: getDeviceType(),\n device_vendor: manufacturer ?? undefined,\n device_model_id: modelId ?? undefined,\n device_pixel_ratio: PixelRatio.get(),\n screen_width,\n screen_height,\n screen_resolution: `${screen_width}x${screen_height}`,\n release: config.release,\n language: getLocales().at(0)?.languageTag ?? 'en',\n time_zone: getCalendars().at(0)?.timeZone ?? 'UTC',\n // ads\n advertising_id: getAdvertisingId() ?? undefined,\n install_referrer,\n // utm params: from the install referrer, on the launch that claimed it\n utm_source: params.get('utm_source') ?? undefined,\n utm_medium: params.get('utm_medium') ?? undefined,\n utm_campaign: params.get('utm_campaign') ?? undefined,\n utm_term: params.get('utm_term') ?? undefined,\n utm_content: params.get('utm_content') ?? undefined,\n utm_id: params.get('utm_id') ?? undefined,\n utm_source_platform: params.get('utm_source_platform') ?? undefined,\n utm_creative_format: params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic: params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF;;;;;;AAOA,IAAI;AACJ,IAAI;AAEJ,SAAgB,cAA+B;CAC7C,oBAAoB,gBAAgB,CAAC,CAAC,OAAO,UAAmB;EAC9D,kBAAkB,KAAA;EAClB,MAAM;CACR,CAAC;CACD,OAAO;AACT;AAEA,SAAS,qBAAkD;CACzD,IAAIA,aAAAA,SAAS,OAAO,WAAW,OAAO,QAAQ,QAAQ,KAAA,CAAS;CAC/D,4BAAA,GAA2BC,iBAAAA,wBAAAA,CAAwB,CAAC,CAAC,OAAO,UAAmB;EAC7E,yBAAyB,KAAA;EACzB,MAAM;CACR,CAAC;CACD,OAAO;AACT;AAEA,eAAe,kBAAmC;CAChD,IAAI,WAA0B;CAC9B,IAAID,aAAAA,SAAS,OAAO,OAClB,WAAW,OAAA,GAAME,iBAAAA,uBAAAA,CAAuB;MACnC,IAAIF,aAAAA,SAAS,OAAO,WACzB,YAAA,GAAWG,iBAAAA,aAAAA,CAAa;CAE1B,IAAI,CAAC,UAAU;EACb,WAAW,aAAa,QAAQ,WAAW;EAC3C,IAAI,CAAC,UAAU;GACb,YAAA,GAAWC,YAAAA,WAAAA,CAAW;GACtB,aAAa,QAAQ,aAAa,QAAQ;EAC5C;CACF;CACA,OAAO;AACT;AAEA,SAAgB,gBAAoC;CAClD,QAAQC,YAAAA,YAAR;EACE,KAAKC,YAAAA,WAAW,OACd,OAAO;EACT,KAAKA,YAAAA,WAAW,QACd,OAAO;EACT,KAAKA,YAAAA,WAAW,SACd,OAAO;EACT,KAAKA,YAAAA,WAAW,IACd,OAAO;EACT,SACE;CACJ;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,IAAI;AAEJ,SAAS,uBAAgC;CACvC,IAAIC,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,2BAA2B,GAAG,OAAO;CACrE,oBAAA,OAAO,QAAQ,QAAQA,0BAAAA,KAAK,8CAA6B,IAAI,KAAK,EAAA,CAAE,YAAY,CAAC;CACjF,OAAO;AACT;AAEA,eAAsB,UAA8B;CAClD,MAAM,SAASC,aAAAA,WAAW,IAAI,QAAQ;CACtC,MAAM,eAAe,KAAK,MAAM,OAAO,KAAK;CAC5C,MAAM,gBAAgB,KAAK,MAAM,OAAO,MAAM;CAO9C,MAAM,mBAAmB,MAAM,mBAAmB;CAClD,IAAI,oBAAoB,kBAAkB,KAAA,GAAW,gBAAgB,qBAAqB;CAC1F,MAAM,SAAS,IAAIC,0BAAAA,gBAAgB,gBAAgB,mBAAmB,KAAA,CAAS;
|
|
1
|
+
{"version":3,"file":"setup.cjs","names":["Platform","getInstallReferrerAsync","getIosIdForVendorAsync","getAndroidId","randomUUID","deviceType","DeviceType","config","keys","Dimensions","URLSearchParams","osName","osVersion","modelName","manufacturer","modelId","PixelRatio","getLocales","getCalendars","getAdvertisingId"],"sources":["../../src/native/setup.ts"],"sourcesContent":["import 'expo-sqlite/localStorage/install';\nimport { getAndroidId, getInstallReferrerAsync, getIosIdForVendorAsync } from 'expo-application';\nimport { randomUUID } from 'expo-crypto';\nimport {\n DeviceType,\n deviceType,\n manufacturer,\n modelId,\n modelName,\n osName,\n osVersion,\n} from 'expo-device';\nimport { getCalendars, getLocales } from 'expo-localization';\nimport { getAdvertisingId } from 'expo-tracking-transparency';\nimport { Dimensions, PixelRatio, Platform } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport { keys } from '../constants/storage';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n\n/**\n * `getTags` runs once per event now, and both of these reach for a native module. Neither answer\n * can change while the app is running, so each is resolved once and the promise is reused. A\n * failed lookup is not cached, so the next event tries again.\n */\nlet deviceIdPromise: Promise<string> | undefined;\nlet installReferrerPromise: Promise<string | undefined> | undefined;\n\nexport function getDeviceId(): Promise<string> {\n deviceIdPromise ??= resolveDeviceId().catch((error: unknown) => {\n deviceIdPromise = undefined;\n throw error;\n });\n return deviceIdPromise;\n}\n\nfunction getInstallReferrer(): Promise<string | undefined> {\n if (Platform.OS !== 'android') return Promise.resolve(undefined);\n installReferrerPromise ??= getInstallReferrerAsync().catch((error: unknown) => {\n installReferrerPromise = undefined;\n throw error;\n });\n return installReferrerPromise;\n}\n\nasync function resolveDeviceId(): Promise<string> {\n let deviceId: string | null = null;\n if (Platform.OS === 'ios') {\n deviceId = await getIosIdForVendorAsync();\n } else if (Platform.OS === 'android') {\n deviceId = getAndroidId();\n }\n if (!deviceId) {\n deviceId = localStorage.getItem('device_id');\n if (!deviceId) {\n deviceId = randomUUID();\n localStorage.setItem('device_id', deviceId);\n }\n }\n return deviceId;\n}\n\nexport function getDeviceType(): string | undefined {\n switch (deviceType) {\n case DeviceType.PHONE:\n return 'mobile';\n case DeviceType.TABLET:\n return 'tablet';\n case DeviceType.DESKTOP:\n return 'desktop';\n case DeviceType.TV:\n return 'smarttv';\n default:\n return undefined;\n }\n}\n\n/**\n * The install referrer's utm belongs to one launch: the first one that has the referrer in hand\n * — normally the install launch, since `first_open` is the first event the app tracks and\n * tracking it builds the first tags. That launch claims the referrer by writing a marker of its\n * own, and holds the claim for the rest of the process, so every event of the launch and the\n * visitor created from it carry the utm; every later launch finds the marker and sends the raw\n * `install_referrer` alone. Cleared storage and a reinstall lose the marker and claim again,\n * exactly as they make `first_open` fire again.\n *\n * Claimed only once a referrer has actually been resolved. The Install Referrer API needs the\n * Play Store service, which is at its least available right after an install; a launch that\n * could not reach it must not spend the claim on nothing, because the referrer stays readable\n * for 90 days and a later launch can still take it — late attribution, rather than none. iOS\n * has no referrer and so never claims.\n *\n * A marker of its own rather than `first_open_time`, so that nothing here depends on when the\n * hook writes that one relative to the first `getTags`. The storage read waits for that call:\n * `setupAnalytics` and this module's evaluation can run where no storage exists.\n */\nlet installLaunch: boolean | undefined;\n\nfunction claimInstallReferrer(): boolean {\n if (config.storage.getItem(keys.install_referrer_claim_time)) return false;\n config.storage.setItem(keys.install_referrer_claim_time, new Date().toISOString());\n return true;\n}\n\nexport async function getTags(): Promise<TrackTags> {\n const screen = Dimensions.get('screen');\n const screen_width = Math.floor(screen.width);\n const screen_height = Math.floor(screen.height);\n\n // The install referrer never changes, and it used to be spread into `utm_*` on every launch —\n // so every session of an Android install reported the install campaign as its own acquisition\n // for as long as the app stayed installed, and a report reading a session's tags could not tell\n // the install from the thousandth open. The campaign is the install's touch, not every\n // session's.\n const install_referrer = await getInstallReferrer();\n if (install_referrer && installLaunch === undefined) installLaunch = claimInstallReferrer();\n const params = new URLSearchParams(installLaunch ? install_referrer : undefined);\n const opening = await config.deepLink?.getTags();\n\n const tags: TrackTags = {\n os: `${osName} ${osVersion}`,\n os_name: osName ?? undefined,\n os_version: osVersion ?? undefined,\n device: modelName ?? undefined,\n device_id: await getDeviceId(),\n device_type: getDeviceType(),\n device_vendor: manufacturer ?? undefined,\n device_model_id: modelId ?? undefined,\n device_pixel_ratio: PixelRatio.get(),\n screen_width,\n screen_height,\n screen_resolution: `${screen_width}x${screen_height}`,\n release: config.release,\n language: getLocales().at(0)?.languageTag ?? 'en',\n time_zone: getCalendars().at(0)?.timeZone ?? 'UTC',\n // ads\n advertising_id: getAdvertisingId() ?? undefined,\n install_referrer,\n // utm params: from the install referrer, on the launch that claimed it\n utm_source: params.get('utm_source') ?? undefined,\n utm_medium: params.get('utm_medium') ?? undefined,\n utm_campaign: params.get('utm_campaign') ?? undefined,\n utm_term: params.get('utm_term') ?? undefined,\n utm_content: params.get('utm_content') ?? undefined,\n utm_id: params.get('utm_id') ?? undefined,\n utm_source_platform: params.get('utm_source_platform') ?? undefined,\n utm_creative_format: params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic: params.get('utm_marketing_tactic') ?? undefined,\n // the link that opened the app (`setupAnalytics({ deepLink })`): its URL, utm and click ids,\n // over the install referrer's\n ...opening,\n };\n\n cache.tags = tags;\n return tags;\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF;;;;;;AAOA,IAAI;AACJ,IAAI;AAEJ,SAAgB,cAA+B;CAC7C,oBAAoB,gBAAgB,CAAC,CAAC,OAAO,UAAmB;EAC9D,kBAAkB,KAAA;EAClB,MAAM;CACR,CAAC;CACD,OAAO;AACT;AAEA,SAAS,qBAAkD;CACzD,IAAIA,aAAAA,SAAS,OAAO,WAAW,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
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { cache, config } from "../setup/index.mjs";
|
|
2
2
|
import { keys } from "../constants/storage.mjs";
|
|
3
3
|
import { Dimensions, PixelRatio, Platform } from "react-native";
|
|
4
|
+
import { URLSearchParams } from "react-native-url-polyfill";
|
|
4
5
|
import { getAndroidId, getInstallReferrerAsync, getIosIdForVendorAsync } from "expo-application";
|
|
5
6
|
import { DeviceType, deviceType, manufacturer, modelId, modelName, osName, osVersion } from "expo-device";
|
|
6
7
|
import { getCalendars, getLocales } from "expo-localization";
|
|
7
8
|
import "expo-sqlite/localStorage/install";
|
|
8
9
|
import { randomUUID } from "expo-crypto";
|
|
9
10
|
import { getAdvertisingId } from "expo-tracking-transparency";
|
|
10
|
-
import { URLSearchParams } from "react-native-url-polyfill";
|
|
11
11
|
//#region src/native/setup.ts
|
|
12
12
|
const map = /* @__PURE__ */ new Map();
|
|
13
13
|
const storage = {
|
|
@@ -104,6 +104,7 @@ async function getTags() {
|
|
|
104
104
|
const install_referrer = await getInstallReferrer();
|
|
105
105
|
if (install_referrer && installLaunch === void 0) installLaunch = claimInstallReferrer();
|
|
106
106
|
const params = new URLSearchParams(installLaunch ? install_referrer : void 0);
|
|
107
|
+
const opening = await config.deepLink?.getTags();
|
|
107
108
|
const tags = {
|
|
108
109
|
os: `${osName} ${osVersion}`,
|
|
109
110
|
os_name: osName ?? void 0,
|
|
@@ -130,7 +131,8 @@ async function getTags() {
|
|
|
130
131
|
utm_id: params.get("utm_id") ?? void 0,
|
|
131
132
|
utm_source_platform: params.get("utm_source_platform") ?? void 0,
|
|
132
133
|
utm_creative_format: params.get("utm_creative_format") ?? void 0,
|
|
133
|
-
utm_marketing_tactic: params.get("utm_marketing_tactic") ?? void 0
|
|
134
|
+
utm_marketing_tactic: params.get("utm_marketing_tactic") ?? void 0,
|
|
135
|
+
...opening
|
|
134
136
|
};
|
|
135
137
|
cache.tags = tags;
|
|
136
138
|
return tags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/native/setup.ts"],"sourcesContent":["import 'expo-sqlite/localStorage/install';\nimport { getAndroidId, getInstallReferrerAsync, getIosIdForVendorAsync } from 'expo-application';\nimport { randomUUID } from 'expo-crypto';\nimport {\n DeviceType,\n deviceType,\n manufacturer,\n modelId,\n modelName,\n osName,\n osVersion,\n} from 'expo-device';\nimport { getCalendars, getLocales } from 'expo-localization';\nimport { getAdvertisingId } from 'expo-tracking-transparency';\nimport { Dimensions, PixelRatio, Platform } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport { keys } from '../constants/storage';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n\n/**\n * `getTags` runs once per event now, and both of these reach for a native module. Neither answer\n * can change while the app is running, so each is resolved once and the promise is reused. A\n * failed lookup is not cached, so the next event tries again.\n */\nlet deviceIdPromise: Promise<string> | undefined;\nlet installReferrerPromise: Promise<string | undefined> | undefined;\n\nexport function getDeviceId(): Promise<string> {\n deviceIdPromise ??= resolveDeviceId().catch((error: unknown) => {\n deviceIdPromise = undefined;\n throw error;\n });\n return deviceIdPromise;\n}\n\nfunction getInstallReferrer(): Promise<string | undefined> {\n if (Platform.OS !== 'android') return Promise.resolve(undefined);\n installReferrerPromise ??= getInstallReferrerAsync().catch((error: unknown) => {\n installReferrerPromise = undefined;\n throw error;\n });\n return installReferrerPromise;\n}\n\nasync function resolveDeviceId(): Promise<string> {\n let deviceId: string | null = null;\n if (Platform.OS === 'ios') {\n deviceId = await getIosIdForVendorAsync();\n } else if (Platform.OS === 'android') {\n deviceId = getAndroidId();\n }\n if (!deviceId) {\n deviceId = localStorage.getItem('device_id');\n if (!deviceId) {\n deviceId = randomUUID();\n localStorage.setItem('device_id', deviceId);\n }\n }\n return deviceId;\n}\n\nexport function getDeviceType(): string | undefined {\n switch (deviceType) {\n case DeviceType.PHONE:\n return 'mobile';\n case DeviceType.TABLET:\n return 'tablet';\n case DeviceType.DESKTOP:\n return 'desktop';\n case DeviceType.TV:\n return 'smarttv';\n default:\n return undefined;\n }\n}\n\n/**\n * The install referrer's utm belongs to one launch: the first one that has the referrer in hand\n * — normally the install launch, since `first_open` is the first event the app tracks and\n * tracking it builds the first tags. That launch claims the referrer by writing a marker of its\n * own, and holds the claim for the rest of the process, so every event of the launch and the\n * visitor created from it carry the utm; every later launch finds the marker and sends the raw\n * `install_referrer` alone. Cleared storage and a reinstall lose the marker and claim again,\n * exactly as they make `first_open` fire again.\n *\n * Claimed only once a referrer has actually been resolved. The Install Referrer API needs the\n * Play Store service, which is at its least available right after an install; a launch that\n * could not reach it must not spend the claim on nothing, because the referrer stays readable\n * for 90 days and a later launch can still take it — late attribution, rather than none. iOS\n * has no referrer and so never claims.\n *\n * A marker of its own rather than `first_open_time`, so that nothing here depends on when the\n * hook writes that one relative to the first `getTags`. The storage read waits for that call:\n * `setupAnalytics` and this module's evaluation can run where no storage exists.\n */\nlet installLaunch: boolean | undefined;\n\nfunction claimInstallReferrer(): boolean {\n if (config.storage.getItem(keys.install_referrer_claim_time)) return false;\n config.storage.setItem(keys.install_referrer_claim_time, new Date().toISOString());\n return true;\n}\n\nexport async function getTags(): Promise<TrackTags> {\n const screen = Dimensions.get('screen');\n const screen_width = Math.floor(screen.width);\n const screen_height = Math.floor(screen.height);\n\n // The install referrer never changes, and it used to be spread into `utm_*` on every launch —\n // so every session of an Android install reported the install campaign as its own acquisition\n // for as long as the app stayed installed, and a report reading a session's tags could not tell\n // the install from the thousandth open. The campaign is the install's touch, not every\n // session's.\n const install_referrer = await getInstallReferrer();\n if (install_referrer && installLaunch === undefined) installLaunch = claimInstallReferrer();\n const params = new URLSearchParams(installLaunch ? install_referrer : undefined);\n\n const tags: TrackTags = {\n os: `${osName} ${osVersion}`,\n os_name: osName ?? undefined,\n os_version: osVersion ?? undefined,\n device: modelName ?? undefined,\n device_id: await getDeviceId(),\n device_type: getDeviceType(),\n device_vendor: manufacturer ?? undefined,\n device_model_id: modelId ?? undefined,\n device_pixel_ratio: PixelRatio.get(),\n screen_width,\n screen_height,\n screen_resolution: `${screen_width}x${screen_height}`,\n release: config.release,\n language: getLocales().at(0)?.languageTag ?? 'en',\n time_zone: getCalendars().at(0)?.timeZone ?? 'UTC',\n // ads\n advertising_id: getAdvertisingId() ?? undefined,\n install_referrer,\n // utm params: from the install referrer, on the launch that claimed it\n utm_source: params.get('utm_source') ?? undefined,\n utm_medium: params.get('utm_medium') ?? undefined,\n utm_campaign: params.get('utm_campaign') ?? undefined,\n utm_term: params.get('utm_term') ?? undefined,\n utm_content: params.get('utm_content') ?? undefined,\n utm_id: params.get('utm_id') ?? undefined,\n utm_source_platform: params.get('utm_source_platform') ?? undefined,\n utm_creative_format: params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic: params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF;;;;;;AAOA,IAAI;AACJ,IAAI;AAEJ,SAAgB,cAA+B;CAC7C,oBAAoB,gBAAgB,CAAC,C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B,KAAA,CAAS;
|
|
1
|
+
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/native/setup.ts"],"sourcesContent":["import 'expo-sqlite/localStorage/install';\nimport { getAndroidId, getInstallReferrerAsync, getIosIdForVendorAsync } from 'expo-application';\nimport { randomUUID } from 'expo-crypto';\nimport {\n DeviceType,\n deviceType,\n manufacturer,\n modelId,\n modelName,\n osName,\n osVersion,\n} from 'expo-device';\nimport { getCalendars, getLocales } from 'expo-localization';\nimport { getAdvertisingId } from 'expo-tracking-transparency';\nimport { Dimensions, PixelRatio, Platform } from 'react-native';\nimport { URLSearchParams } from 'react-native-url-polyfill';\nimport { keys } from '../constants/storage';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n\n/**\n * `getTags` runs once per event now, and both of these reach for a native module. Neither answer\n * can change while the app is running, so each is resolved once and the promise is reused. A\n * failed lookup is not cached, so the next event tries again.\n */\nlet deviceIdPromise: Promise<string> | undefined;\nlet installReferrerPromise: Promise<string | undefined> | undefined;\n\nexport function getDeviceId(): Promise<string> {\n deviceIdPromise ??= resolveDeviceId().catch((error: unknown) => {\n deviceIdPromise = undefined;\n throw error;\n });\n return deviceIdPromise;\n}\n\nfunction getInstallReferrer(): Promise<string | undefined> {\n if (Platform.OS !== 'android') return Promise.resolve(undefined);\n installReferrerPromise ??= getInstallReferrerAsync().catch((error: unknown) => {\n installReferrerPromise = undefined;\n throw error;\n });\n return installReferrerPromise;\n}\n\nasync function resolveDeviceId(): Promise<string> {\n let deviceId: string | null = null;\n if (Platform.OS === 'ios') {\n deviceId = await getIosIdForVendorAsync();\n } else if (Platform.OS === 'android') {\n deviceId = getAndroidId();\n }\n if (!deviceId) {\n deviceId = localStorage.getItem('device_id');\n if (!deviceId) {\n deviceId = randomUUID();\n localStorage.setItem('device_id', deviceId);\n }\n }\n return deviceId;\n}\n\nexport function getDeviceType(): string | undefined {\n switch (deviceType) {\n case DeviceType.PHONE:\n return 'mobile';\n case DeviceType.TABLET:\n return 'tablet';\n case DeviceType.DESKTOP:\n return 'desktop';\n case DeviceType.TV:\n return 'smarttv';\n default:\n return undefined;\n }\n}\n\n/**\n * The install referrer's utm belongs to one launch: the first one that has the referrer in hand\n * — normally the install launch, since `first_open` is the first event the app tracks and\n * tracking it builds the first tags. That launch claims the referrer by writing a marker of its\n * own, and holds the claim for the rest of the process, so every event of the launch and the\n * visitor created from it carry the utm; every later launch finds the marker and sends the raw\n * `install_referrer` alone. Cleared storage and a reinstall lose the marker and claim again,\n * exactly as they make `first_open` fire again.\n *\n * Claimed only once a referrer has actually been resolved. The Install Referrer API needs the\n * Play Store service, which is at its least available right after an install; a launch that\n * could not reach it must not spend the claim on nothing, because the referrer stays readable\n * for 90 days and a later launch can still take it — late attribution, rather than none. iOS\n * has no referrer and so never claims.\n *\n * A marker of its own rather than `first_open_time`, so that nothing here depends on when the\n * hook writes that one relative to the first `getTags`. The storage read waits for that call:\n * `setupAnalytics` and this module's evaluation can run where no storage exists.\n */\nlet installLaunch: boolean | undefined;\n\nfunction claimInstallReferrer(): boolean {\n if (config.storage.getItem(keys.install_referrer_claim_time)) return false;\n config.storage.setItem(keys.install_referrer_claim_time, new Date().toISOString());\n return true;\n}\n\nexport async function getTags(): Promise<TrackTags> {\n const screen = Dimensions.get('screen');\n const screen_width = Math.floor(screen.width);\n const screen_height = Math.floor(screen.height);\n\n // The install referrer never changes, and it used to be spread into `utm_*` on every launch —\n // so every session of an Android install reported the install campaign as its own acquisition\n // for as long as the app stayed installed, and a report reading a session's tags could not tell\n // the install from the thousandth open. The campaign is the install's touch, not every\n // session's.\n const install_referrer = await getInstallReferrer();\n if (install_referrer && installLaunch === undefined) installLaunch = claimInstallReferrer();\n const params = new URLSearchParams(installLaunch ? install_referrer : undefined);\n const opening = await config.deepLink?.getTags();\n\n const tags: TrackTags = {\n os: `${osName} ${osVersion}`,\n os_name: osName ?? undefined,\n os_version: osVersion ?? undefined,\n device: modelName ?? undefined,\n device_id: await getDeviceId(),\n device_type: getDeviceType(),\n device_vendor: manufacturer ?? undefined,\n device_model_id: modelId ?? undefined,\n device_pixel_ratio: PixelRatio.get(),\n screen_width,\n screen_height,\n screen_resolution: `${screen_width}x${screen_height}`,\n release: config.release,\n language: getLocales().at(0)?.languageTag ?? 'en',\n time_zone: getCalendars().at(0)?.timeZone ?? 'UTC',\n // ads\n advertising_id: getAdvertisingId() ?? undefined,\n install_referrer,\n // utm params: from the install referrer, on the launch that claimed it\n utm_source: params.get('utm_source') ?? undefined,\n utm_medium: params.get('utm_medium') ?? undefined,\n utm_campaign: params.get('utm_campaign') ?? undefined,\n utm_term: params.get('utm_term') ?? undefined,\n utm_content: params.get('utm_content') ?? undefined,\n utm_id: params.get('utm_id') ?? undefined,\n utm_source_platform: params.get('utm_source_platform') ?? undefined,\n utm_creative_format: params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic: params.get('utm_marketing_tactic') ?? undefined,\n // the link that opened the app (`setupAnalytics({ deepLink })`): its URL, utm and click ids,\n // over the install referrer's\n ...opening,\n };\n\n cache.tags = tags;\n return tags;\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAA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
thirdPartyUserSetters: []
|
|
14
|
+
thirdPartyUserSetters: [],
|
|
15
|
+
deepLink: void 0
|
|
15
16
|
};
|
|
16
17
|
function setupAnalytics(init) {
|
|
17
18
|
config.release = init.release;
|
|
@@ -27,6 +28,12 @@ function setupAnalytics(init) {
|
|
|
27
28
|
});
|
|
28
29
|
config.thirdPartyTrackers = init.thirdPartyTrackers ?? [];
|
|
29
30
|
config.thirdPartyUserSetters = init.thirdPartyUserSetters ?? [];
|
|
31
|
+
config.deepLink = init.deepLink;
|
|
32
|
+
try {
|
|
33
|
+
init.deepLink?.listen();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("analytics deepLink.listen failed", error);
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
//#endregion
|
|
32
39
|
exports.cache = cache;
|
package/dist/setup/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type { Environment, Platform, ThirdPartyTracker, TrackTags } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\nexport interface Storage {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n thirdPartyTrackers?: ThirdPartyTracker[];\n thirdPartyUserSetters?: ThirdPartyUserSetter[];\n}\n\ninterface Config {\n release: string;\n endpoint: string;\n storage: Storage;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n thirdPartyTrackers: ThirdPartyTracker[];\n thirdPartyUserSetters: ThirdPartyUserSetter[];\n}\n\ninterface Cache {\n tags: TrackTags | null;\n}\n\nexport const cache: Cache = {\n tags: null,\n};\n\n// oxlint-disable typescript/no-non-null-assertion\nexport const config: Config = {\n endpoint: '',\n release: '0.0.0',\n storage: null!,\n platform: null!,\n environment: null!,\n getTags: null!,\n getDeviceId: null!,\n getHeaders: null!,\n thirdPartyTrackers: [],\n thirdPartyUserSetters: [],\n};\n// oxlint-enable typescript/no-non-null-assertion\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.platform = init.platform;\n config.environment = init.environment;\n config.endpoint = init.endpoint.endsWith('/') ? init.endpoint.slice(0, -1) : init.endpoint;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.getHeaders = async () => ({\n 'Content-Type': 'application/json',\n ...(await init.getHeaders?.()),\n });\n config.thirdPartyTrackers = init.thirdPartyTrackers ?? [];\n config.thirdPartyUserSetters = init.thirdPartyUserSetters ?? [];\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/setup/index.ts"],"sourcesContent":["import type { Environment, Platform, ThirdPartyTracker, TrackTags } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\nexport interface Storage {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n}\n\n/**\n * The link that opened the current visit of an app — a universal link, an app link, a custom\n * scheme — whose URL, utm and click ids land the visit as a web page's URL does.\n * `@shware/analytics/native` provides one (`deepLink`).\n */\nexport interface DeepLink {\n /** Starts following the links that open the app; `setupAnalytics` calls it once. */\n listen: () => void;\n /** The opening link's tags (`page_location`, utm, click ids); empty without one. */\n getTags: () => TrackTags | Promise<TrackTags>;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n thirdPartyTrackers?: ThirdPartyTracker[];\n thirdPartyUserSetters?: ThirdPartyUserSetter[];\n /** An app's opening link, which native's `getTags` merges into every event's tags. */\n deepLink?: DeepLink;\n}\n\ninterface Config {\n release: string;\n endpoint: string;\n storage: Storage;\n platform: Platform;\n environment: Environment;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n getHeaders: () => Record<string, string> | Promise<Record<string, string>>;\n thirdPartyTrackers: ThirdPartyTracker[];\n thirdPartyUserSetters: ThirdPartyUserSetter[];\n deepLink: DeepLink | undefined;\n}\n\ninterface Cache {\n tags: TrackTags | null;\n}\n\nexport const cache: Cache = {\n tags: null,\n};\n\n// oxlint-disable typescript/no-non-null-assertion\nexport const config: Config = {\n endpoint: '',\n release: '0.0.0',\n storage: null!,\n platform: null!,\n environment: null!,\n getTags: null!,\n getDeviceId: null!,\n getHeaders: null!,\n thirdPartyTrackers: [],\n thirdPartyUserSetters: [],\n deepLink: undefined,\n};\n// oxlint-enable typescript/no-non-null-assertion\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.platform = init.platform;\n config.environment = init.environment;\n config.endpoint = init.endpoint.endsWith('/') ? init.endpoint.slice(0, -1) : init.endpoint;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.getHeaders = async () => ({\n 'Content-Type': 'application/json',\n ...(await init.getHeaders?.()),\n });\n config.thirdPartyTrackers = init.thirdPartyTrackers ?? [];\n config.thirdPartyUserSetters = init.thirdPartyUserSetters ?? [];\n config.deepLink = init.deepLink;\n // Logged, not thrown: the links are worth less than the setup they would break.\n try {\n init.deepLink?.listen();\n } catch (error) {\n console.error('analytics deepLink.listen failed', error);\n }\n}\n"],"mappings":";;AAqDA,MAAa,QAAe,EAC1B,MAAM,KACR;AAGA,MAAa,SAAiB;CAC5B,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,aAAa;CACb,SAAS;CACT,aAAa;CACb,YAAY;CACZ,oBAAoB,CAAC;CACrB,uBAAuB,CAAC;CACxB,UAAU,KAAA;AACZ;AAGA,SAAgB,eAAe,MAAe;CAC5C,OAAO,UAAU,KAAK;CACtB,OAAO,UAAU,KAAK;CACtB,OAAO,WAAW,KAAK;CACvB,OAAO,cAAc,KAAK;CAC1B,OAAO,WAAW,KAAK,SAAS,SAAS,GAAG,IAAI,KAAK,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK;CAClF,OAAO,UAAU,KAAK;CACtB,OAAO,cAAc,KAAK;CAC1B,OAAO,aAAa,aAAa;EAC/B,gBAAgB;EAChB,GAAI,MAAM,KAAK,aAAa;CAC9B;CACA,OAAO,qBAAqB,KAAK,sBAAsB,CAAC;CACxD,OAAO,wBAAwB,KAAK,yBAAyB,CAAC;CAC9D,OAAO,WAAW,KAAK;CAEvB,IAAI;EACF,KAAK,UAAU,OAAO;CACxB,SAAS,OAAO;EACd,QAAQ,MAAM,oCAAoC,KAAK;CACzD;AACF"}
|
package/dist/setup/index.d.cts
CHANGED
|
@@ -5,6 +5,17 @@ export interface Storage {
|
|
|
5
5
|
getItem: (key: string) => string | null;
|
|
6
6
|
setItem: (key: string, value: string) => void;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* The link that opened the current visit of an app — a universal link, an app link, a custom
|
|
10
|
+
* scheme — whose URL, utm and click ids land the visit as a web page's URL does.
|
|
11
|
+
* `@shware/analytics/native` provides one (`deepLink`).
|
|
12
|
+
*/
|
|
13
|
+
export interface DeepLink {
|
|
14
|
+
/** Starts following the links that open the app; `setupAnalytics` calls it once. */
|
|
15
|
+
listen: () => void;
|
|
16
|
+
/** The opening link's tags (`page_location`, utm, click ids); empty without one. */
|
|
17
|
+
getTags: () => TrackTags | Promise<TrackTags>;
|
|
18
|
+
}
|
|
8
19
|
export interface Options {
|
|
9
20
|
release: string;
|
|
10
21
|
storage: Storage;
|
|
@@ -16,6 +27,8 @@ export interface Options {
|
|
|
16
27
|
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
17
28
|
thirdPartyTrackers?: ThirdPartyTracker[];
|
|
18
29
|
thirdPartyUserSetters?: ThirdPartyUserSetter[];
|
|
30
|
+
/** An app's opening link, which native's `getTags` merges into every event's tags. */
|
|
31
|
+
deepLink?: DeepLink;
|
|
19
32
|
}
|
|
20
33
|
interface Config {
|
|
21
34
|
release: string;
|
|
@@ -28,6 +41,7 @@ interface Config {
|
|
|
28
41
|
getHeaders: () => Record<string, string> | Promise<Record<string, string>>;
|
|
29
42
|
thirdPartyTrackers: ThirdPartyTracker[];
|
|
30
43
|
thirdPartyUserSetters: ThirdPartyUserSetter[];
|
|
44
|
+
deepLink: DeepLink | undefined;
|
|
31
45
|
}
|
|
32
46
|
interface Cache {
|
|
33
47
|
tags: TrackTags | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/setup/index.ts"],"mappings":";;;iBAGiB;EACf,UAAU;EACV,UAAU,aAAa;;;;;;;iBAQR;;EAEf;;EAEA,eAAe,YAAY,QAAQ;;iBAGpB;EACf;EACA,SAAS;EACT;EACA,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,mBAAmB,yBAAyB,QAAQ;EACpD,qBAAqB;EACrB,wBAAwB;;EAExB,WAAW;;UAGH;EACR;EACA;EACA,SAAS;EACT,UAAU;EACV,aAAa;EACb,eAAe,YAAY,QAAQ;EACnC,4BAA4B;EAC5B,kBAAkB,yBAAyB,QAAQ;EACnD,oBAAoB;EACpB,uBAAuB;EACvB,UAAU;;UAGF;EACR,MAAM;;qBAGK,OAAO;qBAKP,QAAQ;wBAeL,eAAe,MAAM"}
|