@shware/analytics 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.cjs +102 -5
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +21 -2
- package/dist/next/index.d.ts +21 -2
- package/dist/next/index.mjs +89 -4
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +91 -4
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts +21 -2
- package/dist/react-router/index.d.ts +21 -2
- package/dist/react-router/index.mjs +88 -3
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/schema/index.d.cts +8 -8
- package/dist/schema/index.d.ts +8 -8
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +3 -1
- package/dist/setup/index.d.ts +3 -1
- package/dist/setup/index.mjs.map +1 -1
- package/dist/track/fbq.cjs +143 -0
- package/dist/track/fbq.cjs.map +1 -0
- package/dist/track/fbq.d.cts +278 -0
- package/dist/track/fbq.d.ts +278 -0
- package/dist/track/fbq.mjs +117 -0
- package/dist/track/fbq.mjs.map +1 -0
- package/dist/track/{ga.cjs → gtag.cjs} +5 -5
- package/dist/track/gtag.cjs.map +1 -0
- package/dist/track/gtag.d.cts +463 -0
- package/dist/track/gtag.d.ts +463 -0
- package/dist/track/{ga.mjs → gtag.mjs} +2 -2
- package/dist/track/gtag.mjs.map +1 -0
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts +3 -2
- package/dist/track/index.d.ts +3 -2
- package/dist/track/index.mjs.map +1 -1
- package/dist/{types/index.cjs → track/types.cjs} +2 -2
- package/dist/track/types.cjs.map +1 -0
- package/dist/track/types.d.cts +87 -0
- package/dist/track/types.d.ts +87 -0
- package/dist/track/types.mjs +1 -0
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.d.cts +1 -1
- package/dist/visitor/index.d.ts +1 -1
- package/dist/visitor/index.mjs.map +1 -1
- package/dist/visitor/types.cjs +19 -0
- package/dist/visitor/types.cjs.map +1 -0
- package/dist/visitor/types.d.cts +16 -0
- package/dist/visitor/types.d.ts +16 -0
- package/dist/visitor/types.mjs +1 -0
- package/dist/visitor/types.mjs.map +1 -0
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +2 -1
- package/dist/web/index.d.ts +2 -1
- package/dist/web/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/track/ga.cjs.map +0 -1
- package/dist/track/ga.d.cts +0 -4
- package/dist/track/ga.d.ts +0 -4
- package/dist/track/ga.mjs.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -327
- package/dist/types/index.d.ts +0 -327
- package/dist/types/index.mjs +0 -1
- /package/dist/{types/index.mjs.map → track/types.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["import type { EventName, TrackName, TrackProperties, Item } from './types';\nexport type Content = { id: string; quantity: number; [key: string]: unknown };\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport type MatchingParameters = {\n /** Email: Unhashed lowercase or hashed SHA-256 */\n em?: string;\n\n /** First Name: Lowercase letters */\n fn?: string;\n\n /** Last Name: Lowercase letters */\n ln?: string;\n\n /** Phone Number: Digits only including country code and area code */\n ph?: string;\n\n /**\n * External ID: Any unique ID from the advertiser, such as loyalty membership ID, user ID, and\n * external cookie ID.\n */\n external_id?: string;\n\n /** Gender: Single lowercase letter, f or m, if unknown, leave blank */\n ge?: 'f' | 'm' | '';\n\n /** Birthdate: Digits only with birth year, month, then day, YYYYMMDD */\n db?: number;\n\n /** City: Lowercase with any spaces removed, e.g. \"menlopark\" */\n ct?: string;\n\n /** State or Province: Lowercase two-letter state or province code, e.g. \"ca\" */\n st?: string;\n\n /** Zip or Postal Code: String */\n zp?: string;\n\n /** Country: Lowercase two-letter country code, e.g. \"us\" */\n country?: string;\n\n /** Client IP Address: Do not hash. */\n client_ip_address?: string;\n\n /** Client User Agent: Do not hash. */\n client_user_agent?: string;\n\n /**\n * Click ID: Do not hash.\n * The Facebook click ID value is stored in the _fbc browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value or generate this value from a fbclid\n * query parameter.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${fbclid}.\n */\n fbc?: string;\n\n /**\n * Browser ID: Do not hash.\n * The Facebook browser ID value is stored in the _fbp browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${random_number}.\n */\n fbp?: string;\n\n /**\n * Subscription ID: Do not hash.\n * The subscription ID for the user in this transaction; it is similar to the order ID for an\n * individual product.\n */\n subscription_id?: string;\n\n /**\n * Facebook Login ID: Do not hash.\n * The ID issued by Meta when a person first logs into an instance of an app. This is also known\n * as App-Scoped ID.\n */\n fb_login_id?: number;\n\n /**\n * Lead ID: Do not hash.\n * The ID associated with a lead generated by [Meta's Lead Ads](https://developers.facebook.com/docs/marketing-api/guides/lead-ads).\n */\n lead_id?: number;\n\n /**\n * Install ID: Do not hash.\n * Your install ID. This field represents unique application installation instances.\n * Note: This parameter is for app events only.\n */\n anon_id?: string;\n\n /**\n * Your mobile advertiser ID, the advertising ID from an Android device or the Advertising\n * Identifier (IDFA) from an Apple device.\n */\n madid?: string;\n\n /**\n * Page ID: Do not hash.\n * Your Page ID. Specifies the page ID associated with the event. Use the Facebook page ID of the\n * page associated with the bot.\n */\n page_id?: string;\n\n /**\n * Page Scoped User ID: Do not hash.\n * Specifies the page-scoped user ID associated with the messenger bot that logs the event. Use\n * the page-scoped user ID provided to your webhook.\n */\n page_scoped_user_id?: string;\n\n /**\n * Do not hash.\n * Click ID generated by Meta for ads that click to WhatsApp.\n */\n ctwa_clid?: string;\n\n /**\n * Do not hash.\n * Instagram Account ID that is associated with the business.\n */\n ig_account_id?: string;\n\n /**\n * Do not hash.\n * Users who interact with Instagram are identified by Instagram-Scoped User IDs (IGSID). IGSID\n * can be obtained from this webhook.\n */\n ig_sid?: string;\n};\n\n/**\n * You can include the following predefined object properties with any custom events, and any\n * standard events that support them. Format your parameter object data using JSON. Learn more about\n * event parameters with Blueprint.\n */\nexport type ObjectProperties = {\n content_category?: string;\n content_ids?: string[];\n content_name?: string;\n\n /**\n * Either product or product_group based on the content_ids or contents being passed. If the IDs\n * being passed in content_ids or contents parameter are IDs of products, then the value should be\n * product. If product group IDs are being passed, then the value should be product_group.\n *\n * If no content_type is provided, Meta will match the event to every item that has the same ID,\n * independent of its type.\n */\n content_type?: 'product' | 'product_group' | (string & {});\n contents?: Content[];\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery';\n currency?: string;\n num_items?: number;\n predicted_ltv?: number;\n search_string?: string;\n\n /** Used with the CompleteRegistration event, to show the status of the registration. */\n status?: boolean;\n value?: number;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper\n */\nexport type StandardEvents = {\n AddPaymentInfo: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n AddToCart: {\n content_ids?: string[];\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents\n currency?: string;\n value?: number;\n };\n AddToWishlist: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n CompleteRegistration: {\n currency?: string;\n value?: number;\n method?: string;\n };\n Contact: {};\n CustomizeProduct: {};\n Donate: {};\n FindLocation: {};\n InitiateCheckout: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n num_items?: number;\n value?: number;\n };\n Lead: {\n currency?: string;\n value?: number;\n };\n Purchase: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency: string; // required\n num_items?: number;\n value: number; // required\n };\n Schedule: {};\n Search: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n search_string?: string;\n value?: number;\n };\n StartTrial: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n SubmitApplication: {};\n Subscribe: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n ViewContent: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n value?: number;\n };\n};\n\ntype JSONValue =\n | null\n | string\n | number\n | boolean\n | Array<JSONValue>\n | { [value: string]: JSONValue };\n\nexport type PixelId = `${number}`;\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events\n *\n * We determine if events are identical based on their ID and name. So, for an event to be deduplicated:\n * - In corresponding events, a Meta Pixel's eventID must match the Conversion API's event_id.\n * - In corresponding events, a Meta Pixel's event must match the Conversion API's event_name.\n *\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport interface Fbq {\n /**\n * reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel\n *\n * Call init the normal default way first:\n * `fbq('init', 'XXXXX')`\n *\n * And at a later point in time, when you have obtained additional user data, you can call init\n * again basically enriching the already running fbq instance with additional data:\n * `fbq('init', 'XXXXX', { external_id: 1234, em: 'abc@abc.com' } )`\n *\n * Only caveat is that you have to send an event after this additional init call, otherwise the\n * provided data will not be sent to Facebook.\n */\n fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;\n\n /** Enable Manual Only mode. (value = false) */\n fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;\n\n fbq<T extends keyof StandardEvents>(\n type: 'track',\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n fbq(\n type: 'trackCustom',\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq<T extends keyof StandardEvents>(\n type: 'trackSingle',\n pixelId: PixelId,\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq(\n type: 'trackSingleCustom',\n pixelId: PixelId,\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n}\n\n/**\n * Please download this CSV filefor examples of properly normalized and hashed data for the\n * parameters below.\n */\nexport function normalize(parameters: MatchingParameters): MatchingParameters {\n return {\n ...parameters,\n em: parameters.em?.toLowerCase().trim(),\n ph: parameters.ph?.replace(/[\\+\\-\\(\\)\\s]/g, '').replace(/^0+/, ''),\n zp: parameters.zp?.split('-').at(0)?.trim(),\n fn: parameters.fn?.toLowerCase().trim(),\n ln: parameters.ln?.toLowerCase().trim(),\n ct: parameters.ct?.toLowerCase().replace(/[s/-]/g, '').trim(),\n st: parameters.st\n ?.toLowerCase()\n .replace(/[s/-/,.]/g, '')\n .trim(),\n country: parameters.country?.toLowerCase().replace(/[s/-]/g, '').trim(),\n };\n}\n\nfunction mapItems(items?: Item[]): ObjectProperties {\n if (!items) return {};\n const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));\n const contents = items.map(({ item_id, quantity, ...others }) => ({\n id: item_id!,\n quantity: quantity ?? 1,\n ...Object.fromEntries(\n Object.entries(others).map(([key, value]) => [key.replace('item_', ''), value])\n ),\n }));\n\n return {\n content_category: categories.length === 1 ? categories.at(0) : undefined,\n contents,\n content_ids: contents.map((c) => c.id),\n num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n };\n}\n\nexport function mapAndSendFbqEvent<T extends EventName>(\n fbq: Fbq['fbq'],\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n options?: { eventID?: string }\n) {\n if (name === 'add_payment_info') {\n const p = properties as TrackProperties<'add_payment_info'> | undefined;\n fbq(\n 'track',\n 'AddPaymentInfo',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n fbq(\n 'track',\n 'AddToCart',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n fbq(\n 'track',\n 'AddToWishlist',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'login') {\n const p = properties as TrackProperties<'login'> | undefined;\n fbq('track', 'CompleteRegistration', { method: p?.method }, options);\n } else if (name === 'contact') {\n fbq('track', 'Contact', {}, options);\n } else if (name === 'customize_product') {\n fbq('track', 'CustomizeProduct', {}, options);\n } else if (name === 'donate') {\n fbq('track', 'Donate', {}, options);\n } else if (name === 'find_location') {\n fbq('track', 'FindLocation', {}, options);\n } else if (name === 'begin_checkout') {\n const p = properties as TrackProperties<'begin_checkout'> | undefined;\n fbq(\n 'track',\n 'InitiateCheckout',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n fbq('track', 'Lead', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n fbq(\n 'track',\n 'Purchase',\n p ? { currency: p?.currency, value: p?.value, ...mapItems(p?.items) } : undefined,\n options\n );\n } else if (name === 'schedule') {\n fbq('track', 'Schedule', {}, options);\n } else if (name === 'search') {\n const p = properties as TrackProperties<'search'> | undefined;\n fbq('track', 'Search', { search_string: p?.search_term }, options);\n } else if (name === 'trial_begin') {\n const p = properties as TrackProperties<'trial_begin'> | undefined;\n fbq('track', 'StartTrial', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'submit_application') {\n fbq('track', 'SubmitApplication', {}, options);\n } else if (name === 'subscribe') {\n const p = properties as TrackProperties<'subscribe'> | undefined;\n fbq('track', 'Subscribe', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'view_item') {\n const p = properties as TrackProperties<'view_item'> | undefined;\n fbq(\n 'track',\n 'ViewContent',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else {\n fbq('trackCustom', name, properties, options);\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/track/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
20
|
+
// src/track/gtag.ts
|
|
21
|
+
var gtag_exports = {};
|
|
22
|
+
__export(gtag_exports, {
|
|
23
23
|
reservedEventNames: () => reservedEventNames,
|
|
24
24
|
standardEventNames: () => standardEventNames
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(gtag_exports);
|
|
27
27
|
var standardEventNames = [
|
|
28
28
|
"add_payment_info",
|
|
29
29
|
"add_shipping_info",
|
|
@@ -99,4 +99,4 @@ var reservedEventNames = [
|
|
|
99
99
|
reservedEventNames,
|
|
100
100
|
standardEventNames
|
|
101
101
|
});
|
|
102
|
-
//# sourceMappingURL=
|
|
102
|
+
//# sourceMappingURL=gtag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/track/gtag.ts"],"sourcesContent":["export const standardEventNames = [\n 'add_payment_info',\n 'add_shipping_info',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'close_convert_lead',\n 'close_unconvert_lead',\n 'disqualify_lead',\n 'earn_virtual_currency',\n 'generate_lead',\n 'join_group',\n 'level_end',\n 'level_start',\n 'level_up',\n 'login',\n 'post_score',\n 'purchase',\n 'qualify_lead',\n 'refund',\n 'remove_from_cart',\n 'search',\n 'select_content',\n 'select_item',\n 'select_promotion',\n 'share',\n 'sign_up',\n 'spend_virtual_currency',\n 'tutorial_begin',\n 'tutorial_complete',\n 'unlock_achievement',\n 'view_cart',\n 'view_item',\n 'view_item_list',\n 'view_promotion',\n 'working_lead',\n] as const;\n\nexport const reservedEventNames = [\n 'ad_activeview',\n 'ad_click',\n 'ad_exposure',\n 'ad_query',\n 'ad_reward',\n 'adunit_exposure',\n 'app_background',\n 'app_clear_data',\n 'app_exception',\n 'app_remove',\n 'app_store_refund',\n 'app_store_subscription_cancel',\n 'app_store_subscription_convert',\n 'app_store_subscription_renew',\n 'app_update',\n 'app_upgrade',\n 'dynamic_link_app_open',\n 'dynamic_link_app_update',\n 'dynamic_link_first_open',\n 'error',\n 'first_open',\n 'first_visit',\n 'in_app_purchase',\n 'notification_dismiss',\n 'notification_foreground',\n 'notification_open',\n 'notification_receive',\n 'os_update',\n 'session_start',\n 'session_start_with_rollout',\n 'user_engagement',\n];\n\nexport type GaId = `G-${Uppercase<string>}`;\nexport type GtmId = `GTM-${Uppercase<string>}`;\n\nexport type CampaignMedium =\n | 'email'\n | 'organic'\n | 'cpc'\n | 'banner'\n | 'social'\n | 'referral'\n | 'affiliate'\n | 'video'\n | 'display'\n | 'sms'\n | 'push'\n | 'qr'\n | 'audio'\n | (string & {});\n\nexport type CampaignSource =\n | 'google' // don't need to set\n | 'googleads'\n | 'bing'\n | 'bingads'\n | 'metaads'\n | 'facebook'\n | 'twitter'\n | 'linkedin'\n | 'instagram'\n | 'tiktok'\n | 'youtube'\n | 'newsletter'\n | `website_${string}`\n | `affiliate_${string}`\n | (string & {});\n\nexport type Campaign = {\n id?: string;\n name?: string;\n term?: string;\n content?: string;\n medium?: CampaignMedium;\n source?: CampaignSource;\n};\n\nexport type Config = {\n allow_google_signals?: boolean;\n allow_ad_personalization_signals?: boolean;\n\n campaign_content?: string;\n campaign_id?: string;\n campaign_medium?: CampaignMedium;\n campaign_name?: string;\n campaign_source?: CampaignSource;\n campaign_term?: string;\n\n /**\n * @deprecated\n * Key Point: Use the campaign_ prefixed version of each campaign value instead of this field.\n */\n campaign?: Campaign;\n\n client_id?: string;\n content_group?: string;\n\n cookie_domain?: 'none' | 'auto' | string;\n cookie_expires?: number;\n cookie_flags?: string;\n cookie_path?: string;\n cookie_prefix?: string;\n cookie_update?: boolean;\n\n ignore_referrer?: boolean;\n language?: string;\n\n page_location?: string;\n page_referrer?: string;\n page_title?: string;\n\n send_page_view?: boolean;\n screen_resolution?: `${number}x${number}`;\n user_id?: string;\n user_property?: Record<string, string | boolean | number | null | undefined>;\n};\n\nexport type Item = {\n item_id: string;\n item_name: string;\n affiliation?: 'Google Store' | (string & {});\n coupon?: string;\n discount?: number;\n index?: number;\n item_brand?: string;\n item_category?: string;\n item_category2?: string;\n item_category3?: string;\n item_category4?: string;\n item_category5?: string;\n item_list_id?: string;\n item_list_name?: string;\n item_variant?: string;\n location_id?: string;\n price?: number;\n quantity?: number;\n};\n\nexport type PromotionItem = {\n creative_name?: string;\n creative_slot?: string;\n promotion_id?: string;\n promotion_name?: string;\n};\n\n/**\n * ref: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag\n * ref: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event\n * */\nexport type StandardEvents = {\n // Google Analytics 4 Recommended Events\n add_payment_info: {\n currency: string;\n value: number;\n coupon?: string;\n payment_type?: string;\n items: Item[];\n };\n add_shipping_info: {\n currency: string;\n value: number;\n coupon?: string;\n shipping_tier?: string;\n items: Item[];\n };\n add_to_cart: {\n currency: string;\n value: number;\n items: Item[];\n };\n add_to_wishlist: {\n currency: string;\n value: number;\n items: Item[];\n };\n begin_checkout: {\n currency: string;\n value: number;\n coupon?: string;\n items: Item[];\n };\n close_convert_lead: {\n currency: string;\n value: number;\n };\n close_unconvert_lead: {\n currency: string;\n value: number;\n unconvert_lead_reason?: string;\n };\n disqualify_lead: {\n currency: string;\n value: number;\n disqualified_lead_reason?: string;\n };\n earn_virtual_currency: {\n virtual_currency_name?: string;\n value?: number;\n };\n generate_lead: {\n currency: string;\n value: number;\n lead_source?: string;\n };\n join_group: {\n group_id?: string;\n };\n level_end: {\n level_name?: string;\n success?: boolean;\n };\n level_start: {\n level_name?: string;\n };\n level_up: {\n level?: number;\n level_name?: string;\n character?: string;\n };\n login: {\n method?: string;\n };\n post_score: {\n score: number;\n level?: number;\n character?: string;\n };\n purchase: {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number; // Shipping cost associated with a transaction.\n tax?: number;\n items?: Item[];\n };\n qualify_lead: {\n currency: string;\n value: number;\n };\n refund: {\n currency: string;\n value: number;\n transaction_id: string;\n coupon?: string;\n shipping?: number;\n tax?: number;\n items?: Item[];\n };\n remove_from_cart: {\n currency: string;\n value: number;\n items: Item[];\n };\n search: {\n search_term: string;\n };\n select_content: {\n content_type?: string;\n content_id?: string;\n };\n select_item: {\n item_list_id?: string;\n item_list_name?: string;\n items: Item[];\n };\n select_promotion: {\n creative_name?: string;\n creative_slot?: string;\n promotion_id?: string;\n promotion_name?: string;\n items?: (Item & PromotionItem)[];\n };\n share: {\n method?: string;\n content_type?: string;\n item_id?: string;\n };\n sign_up: {\n method?: string;\n };\n spend_virtual_currency: {\n value: number;\n virtual_currency_name: string;\n item_name?: string;\n };\n tutorial_begin: undefined;\n tutorial_complete: undefined;\n unlock_achievement: {\n achievement_id: string;\n };\n view_cart: {\n currency: string;\n value: number;\n items: Item[];\n };\n view_item: {\n currency: string;\n value: number;\n items: Item[];\n };\n view_item_list: {\n currency: string;\n item_list_id?: string;\n item_list_name?: string;\n items: Item[];\n };\n view_promotion: {\n creative_name?: string;\n creative_slot?: string;\n promotion_id?: string;\n promotion_name?: string;\n items: (Item & PromotionItem)[];\n };\n working_lead: {\n currency: string;\n value: number;\n lead_status?: string;\n };\n\n // Firebase Analytics events, event_name 40 characters limit, 25 parameters limit\n ad_impression: {\n value?: number;\n currency?: string;\n ad_format?: string;\n ad_platform?: string;\n ad_source?: string;\n ad_unit_name?: string;\n };\n app_open: undefined;\n campaign_details: {\n source: string;\n medium: string;\n campaign: string;\n term?: string;\n content?: string;\n aclid?: string;\n cp1?: string;\n };\n screen_view: { screen_name?: string; screen_class?: string };\n view_search_results: { search_term: string };\n\n // Added events\n trial_begin: {\n currency: string;\n value: number;\n };\n\n subscribe: {\n currency: string;\n value: number;\n };\n};\n\n/**\n * reference: https://developers.google.com/analytics/devguides/collection/ga4/reference/config\n * reference: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag\n */\nexport interface Gtag {\n /**\n * To disable advertising features based on third-party advertising identifiers, set\n * allow_google_signals to false.\n *\n * @param allow - Whether to allow Google signals.\n * @default true\n */\n gtag(event: 'set', option: 'allow_google_signals', allow: boolean): void;\n\n /**\n * Set to false to disable advertising personalization features.\n *\n * @param allow - Whether to allow ad personalization signals.\n * @default true\n */\n gtag(event: 'set', option: 'allow_ad_personalization_signals', allow: boolean): void;\n\n /**\n * Used for A/B testing and content-targeted ads. Use campaign_content to differentiate ads or\n * links that point to the same URL.\n */\n gtag(event: 'set', option: 'campaign_content', content: string): void;\n\n /**\n * Used to identify which campaign this referral references. Use campaign_id to identify a\n * specific campaign.\n */\n gtag(event: 'set', option: 'campaign_id', id: string): void;\n\n /** Use campaign_medium to identify a medium such as email or cost-per-click. */\n gtag(event: 'set', option: 'campaign_medium', medium: CampaignMedium): void;\n\n /**\n * Used for keyword analysis. Use campaign_name to identify a specific product promotion or\n * strategic campaign.\n */\n gtag(event: 'set', option: 'campaign_name', name: string): void;\n\n /** Use campaign_source to identify a search engine, newsletter name, or other source. */\n gtag(event: 'set', option: 'campaign_source', source: CampaignSource): void;\n\n /** Used for paid search. Use campaign_term to note the keywords for this ad. */\n gtag(event: 'set', option: 'campaign_term', term: string): void;\n\n /**\n * @deprecated\n * Key Point: Use the campaign_ prefixed version of each campaign value instead of this field.\n */\n gtag(event: 'set', option: 'campaign', params: Campaign): void;\n\n /**\n * Pseudonymously identifies a browser instance. By default, this value is stored as part of the\n * first-party Analytics cookie with a two-year expiration.\n */\n gtag(event: 'set', option: 'client_id', id: string): void;\n\n /** example: gtag('set', 'content_group', '/news/sports'); */\n gtag(event: 'set', option: 'content_group', group: string): void;\n\n /**\n * Specifies the domain used to store the analytics cookie.\n * Set to 'none' to set the cookie without specifying a domain.\n * Set to 'auto' (the default value) to set the cookie to the top level domain plus one\n * subdomain (eTLD +1). For example if cookie_domain is set to 'auto' https://example.com would\n * use example.com for the domain, and https://subdomain.example.com would also use example.com\n * for the domain.\n *\n * @param domain - The domain used to store the analytics cookie.\n * @default 'auto'\n */\n gtag(event: 'set', option: 'cookie_domain', domain: 'none' | 'auto' | string): void;\n\n /**\n * Every time a hit is sent to Google Analytics, the cookie expiration time is updated to be the\n * current time plus the value of the cookie_expires field. This means that if you use the default\n * value time of two years (63072000 seconds), and a user visits your site every month, their\n * cookie will never expire.\n *\n * If you set the cookie_expires time to 0 (zero) seconds, the cookie turns into a session based\n * cookie and expires once the current browser session ends.\n *\n * Caution: If you set the cookie to expire too quickly, you will inflate your user count and\n * decrease the quality of your measurement.\n *\n * @param expires - The number of seconds until the cookie expires.\n * @default 63072000\n */\n gtag(event: 'set', option: 'cookie_expires', expires: number): void;\n\n /**\n * Appends additional flags to the cookie when set. Flags must be separated by semicolons. See\n * [write a new cookie](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#write_a_new_cookie) for some examples of flags to set.\n */\n gtag(event: 'set', option: 'cookie_flags', flags: string): void;\n\n /** Specifies the subpath used to store the analytics cookie. */\n gtag(event: 'set', option: 'cookie_path', path: string): void;\n\n /** Specifies a prefix to prepend to analytics cookie names. */\n gtag(event: 'set', option: 'cookie_prefix', prefix: string): void;\n\n /**\n * When cookie_update is set to true, gtag.js will update cookies on each page load. This will\n * update the cookie expiration to be set relative to the most recent visit to the site. For\n * example, if cookie expiration is set to one week, and a user visits using the same browser\n * every five days, the cookie expiration will be updated on each visit and will effectively\n * never expire.\n *\n * When set to false, cookies are not updated on each page load. This has the effect of cookie\n * expiration being relative to the first time a user visited the site.\n *\n * @param update - Whether to update the cookie on each page load.\n * @default true\n */\n gtag(event: 'set', option: 'cookie_update', update: boolean): void;\n\n /**\n * Set to true to indicate to Analytics that the referrer shouldn't be displayed as a traffic\n * source. [Learn when to use this field](https://support.google.com/analytics/answer/10327750#set-parameter)\n *\n * @param ignore - Whether to ignore the referrer.\n * @default false\n */\n gtag(event: 'set', option: 'ignore_referrer', ignore: boolean): void;\n\n /**\n * Specifies the language preference of the user. Defaults to the user's navigator.language value.\n *\n * @param language - The language preference of the user.\n * @default navigator.language\n */\n gtag(event: 'set', option: 'language', language: string): void;\n\n /**\n * Specifies the full URL of the page. Defaults to the user's document.location value.\n *\n * @param location - The full URL of the page. Character limit 1000\n * @default document.location\n */\n gtag(event: 'set', option: 'page_location', location: string): void;\n\n /**\n * Specifies which referral source brought traffic to a page. This value is also used to compute\n * the traffic source. The format of this value is a URL. Defaults to the user's document.referrer\n * value.\n *\n * @param referrer - The referral source. Character limit 420\n * @default document.referrer\n */\n gtag(event: 'set', option: 'page_referrer', referrer: string): void;\n\n /**\n * The title of the page or document. Defaults to the user's document.title value.\n *\n * @param title - The title of the page or document. Character limit 300\n * @default document.title\n */\n gtag(event: 'set', option: 'page_title', title: string): void;\n\n /**\n * Set to false to prevent the default snippet from sending a page_view.\n *\n * @param send - Whether to send a page_view.\n * @default true\n */\n gtag(event: 'set', option: 'send_page_view', send: boolean): void;\n\n /**\n * Specifies the resolution of the screen. Should be two positive integers separated by an x. For\n * example, for an 800px by 600px screen, the value would be 800x600. Calculated from the user's\n * window.screen value.\n *\n * @param resolution - The resolution of the screen.\n * @default window.screen\n */\n gtag(event: 'set', option: 'screen_resolution', resolution: `${number}x${number}`): void;\n\n /**\n * Specifies a known identifier for a user provided by the site owner/library user. It must not\n * itself be PII (personally identifiable information). The value should never be persisted in\n * Google Analytics cookies or other Analytics provided storage.\n *\n * @param userId - The user ID. Character limit 256\n */\n gtag(event: 'set', option: 'user_id', userId: string): void;\n\n /**\n * User properties are attributes that can be used to describe segments of your user base, such\n * as language preference or geographic location. Up to 25 additional user properties can be set\n * per project.\n *\n * @param name - The name of the user property. Character limit 24\n * @param value - The value of the user property. Character limit 36\n */\n gtag(\n event: 'set',\n option: 'user_property',\n properties: Record<string, string | boolean | number | null | undefined>\n ): void;\n\n /**\n * gtag('config', ...) Set for a single stream\n * gtag('set', ...) Set globally\n */\n gtag(event: 'config', gaId: GaId, config?: Config): void;\n\n gtag<T extends string>(\n event: 'event',\n eventName: T extends keyof StandardEvents ? T : string,\n eventParams?: T extends keyof StandardEvents\n ? StandardEvents[T]\n : Record<string, string | number | boolean | null | undefined>\n ): void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
declare const standardEventNames: readonly ["add_payment_info", "add_shipping_info", "add_to_cart", "add_to_wishlist", "begin_checkout", "close_convert_lead", "close_unconvert_lead", "disqualify_lead", "earn_virtual_currency", "generate_lead", "join_group", "level_end", "level_start", "level_up", "login", "post_score", "purchase", "qualify_lead", "refund", "remove_from_cart", "search", "select_content", "select_item", "select_promotion", "share", "sign_up", "spend_virtual_currency", "tutorial_begin", "tutorial_complete", "unlock_achievement", "view_cart", "view_item", "view_item_list", "view_promotion", "working_lead"];
|
|
2
|
+
declare const reservedEventNames: string[];
|
|
3
|
+
type GaId = `G-${Uppercase<string>}`;
|
|
4
|
+
type GtmId = `GTM-${Uppercase<string>}`;
|
|
5
|
+
type CampaignMedium = 'email' | 'organic' | 'cpc' | 'banner' | 'social' | 'referral' | 'affiliate' | 'video' | 'display' | 'sms' | 'push' | 'qr' | 'audio' | (string & {});
|
|
6
|
+
type CampaignSource = 'google' | 'googleads' | 'bing' | 'bingads' | 'metaads' | 'facebook' | 'twitter' | 'linkedin' | 'instagram' | 'tiktok' | 'youtube' | 'newsletter' | `website_${string}` | `affiliate_${string}` | (string & {});
|
|
7
|
+
type Campaign = {
|
|
8
|
+
id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
term?: string;
|
|
11
|
+
content?: string;
|
|
12
|
+
medium?: CampaignMedium;
|
|
13
|
+
source?: CampaignSource;
|
|
14
|
+
};
|
|
15
|
+
type Config = {
|
|
16
|
+
allow_google_signals?: boolean;
|
|
17
|
+
allow_ad_personalization_signals?: boolean;
|
|
18
|
+
campaign_content?: string;
|
|
19
|
+
campaign_id?: string;
|
|
20
|
+
campaign_medium?: CampaignMedium;
|
|
21
|
+
campaign_name?: string;
|
|
22
|
+
campaign_source?: CampaignSource;
|
|
23
|
+
campaign_term?: string;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated
|
|
26
|
+
* Key Point: Use the campaign_ prefixed version of each campaign value instead of this field.
|
|
27
|
+
*/
|
|
28
|
+
campaign?: Campaign;
|
|
29
|
+
client_id?: string;
|
|
30
|
+
content_group?: string;
|
|
31
|
+
cookie_domain?: 'none' | 'auto' | string;
|
|
32
|
+
cookie_expires?: number;
|
|
33
|
+
cookie_flags?: string;
|
|
34
|
+
cookie_path?: string;
|
|
35
|
+
cookie_prefix?: string;
|
|
36
|
+
cookie_update?: boolean;
|
|
37
|
+
ignore_referrer?: boolean;
|
|
38
|
+
language?: string;
|
|
39
|
+
page_location?: string;
|
|
40
|
+
page_referrer?: string;
|
|
41
|
+
page_title?: string;
|
|
42
|
+
send_page_view?: boolean;
|
|
43
|
+
screen_resolution?: `${number}x${number}`;
|
|
44
|
+
user_id?: string;
|
|
45
|
+
user_property?: Record<string, string | boolean | number | null | undefined>;
|
|
46
|
+
};
|
|
47
|
+
type Item = {
|
|
48
|
+
item_id: string;
|
|
49
|
+
item_name: string;
|
|
50
|
+
affiliation?: 'Google Store' | (string & {});
|
|
51
|
+
coupon?: string;
|
|
52
|
+
discount?: number;
|
|
53
|
+
index?: number;
|
|
54
|
+
item_brand?: string;
|
|
55
|
+
item_category?: string;
|
|
56
|
+
item_category2?: string;
|
|
57
|
+
item_category3?: string;
|
|
58
|
+
item_category4?: string;
|
|
59
|
+
item_category5?: string;
|
|
60
|
+
item_list_id?: string;
|
|
61
|
+
item_list_name?: string;
|
|
62
|
+
item_variant?: string;
|
|
63
|
+
location_id?: string;
|
|
64
|
+
price?: number;
|
|
65
|
+
quantity?: number;
|
|
66
|
+
};
|
|
67
|
+
type PromotionItem = {
|
|
68
|
+
creative_name?: string;
|
|
69
|
+
creative_slot?: string;
|
|
70
|
+
promotion_id?: string;
|
|
71
|
+
promotion_name?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* ref: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag
|
|
75
|
+
* ref: https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event
|
|
76
|
+
* */
|
|
77
|
+
type StandardEvents = {
|
|
78
|
+
add_payment_info: {
|
|
79
|
+
currency: string;
|
|
80
|
+
value: number;
|
|
81
|
+
coupon?: string;
|
|
82
|
+
payment_type?: string;
|
|
83
|
+
items: Item[];
|
|
84
|
+
};
|
|
85
|
+
add_shipping_info: {
|
|
86
|
+
currency: string;
|
|
87
|
+
value: number;
|
|
88
|
+
coupon?: string;
|
|
89
|
+
shipping_tier?: string;
|
|
90
|
+
items: Item[];
|
|
91
|
+
};
|
|
92
|
+
add_to_cart: {
|
|
93
|
+
currency: string;
|
|
94
|
+
value: number;
|
|
95
|
+
items: Item[];
|
|
96
|
+
};
|
|
97
|
+
add_to_wishlist: {
|
|
98
|
+
currency: string;
|
|
99
|
+
value: number;
|
|
100
|
+
items: Item[];
|
|
101
|
+
};
|
|
102
|
+
begin_checkout: {
|
|
103
|
+
currency: string;
|
|
104
|
+
value: number;
|
|
105
|
+
coupon?: string;
|
|
106
|
+
items: Item[];
|
|
107
|
+
};
|
|
108
|
+
close_convert_lead: {
|
|
109
|
+
currency: string;
|
|
110
|
+
value: number;
|
|
111
|
+
};
|
|
112
|
+
close_unconvert_lead: {
|
|
113
|
+
currency: string;
|
|
114
|
+
value: number;
|
|
115
|
+
unconvert_lead_reason?: string;
|
|
116
|
+
};
|
|
117
|
+
disqualify_lead: {
|
|
118
|
+
currency: string;
|
|
119
|
+
value: number;
|
|
120
|
+
disqualified_lead_reason?: string;
|
|
121
|
+
};
|
|
122
|
+
earn_virtual_currency: {
|
|
123
|
+
virtual_currency_name?: string;
|
|
124
|
+
value?: number;
|
|
125
|
+
};
|
|
126
|
+
generate_lead: {
|
|
127
|
+
currency: string;
|
|
128
|
+
value: number;
|
|
129
|
+
lead_source?: string;
|
|
130
|
+
};
|
|
131
|
+
join_group: {
|
|
132
|
+
group_id?: string;
|
|
133
|
+
};
|
|
134
|
+
level_end: {
|
|
135
|
+
level_name?: string;
|
|
136
|
+
success?: boolean;
|
|
137
|
+
};
|
|
138
|
+
level_start: {
|
|
139
|
+
level_name?: string;
|
|
140
|
+
};
|
|
141
|
+
level_up: {
|
|
142
|
+
level?: number;
|
|
143
|
+
level_name?: string;
|
|
144
|
+
character?: string;
|
|
145
|
+
};
|
|
146
|
+
login: {
|
|
147
|
+
method?: string;
|
|
148
|
+
};
|
|
149
|
+
post_score: {
|
|
150
|
+
score: number;
|
|
151
|
+
level?: number;
|
|
152
|
+
character?: string;
|
|
153
|
+
};
|
|
154
|
+
purchase: {
|
|
155
|
+
currency: string;
|
|
156
|
+
value: number;
|
|
157
|
+
transaction_id: string;
|
|
158
|
+
coupon?: string;
|
|
159
|
+
shipping?: number;
|
|
160
|
+
tax?: number;
|
|
161
|
+
items?: Item[];
|
|
162
|
+
};
|
|
163
|
+
qualify_lead: {
|
|
164
|
+
currency: string;
|
|
165
|
+
value: number;
|
|
166
|
+
};
|
|
167
|
+
refund: {
|
|
168
|
+
currency: string;
|
|
169
|
+
value: number;
|
|
170
|
+
transaction_id: string;
|
|
171
|
+
coupon?: string;
|
|
172
|
+
shipping?: number;
|
|
173
|
+
tax?: number;
|
|
174
|
+
items?: Item[];
|
|
175
|
+
};
|
|
176
|
+
remove_from_cart: {
|
|
177
|
+
currency: string;
|
|
178
|
+
value: number;
|
|
179
|
+
items: Item[];
|
|
180
|
+
};
|
|
181
|
+
search: {
|
|
182
|
+
search_term: string;
|
|
183
|
+
};
|
|
184
|
+
select_content: {
|
|
185
|
+
content_type?: string;
|
|
186
|
+
content_id?: string;
|
|
187
|
+
};
|
|
188
|
+
select_item: {
|
|
189
|
+
item_list_id?: string;
|
|
190
|
+
item_list_name?: string;
|
|
191
|
+
items: Item[];
|
|
192
|
+
};
|
|
193
|
+
select_promotion: {
|
|
194
|
+
creative_name?: string;
|
|
195
|
+
creative_slot?: string;
|
|
196
|
+
promotion_id?: string;
|
|
197
|
+
promotion_name?: string;
|
|
198
|
+
items?: (Item & PromotionItem)[];
|
|
199
|
+
};
|
|
200
|
+
share: {
|
|
201
|
+
method?: string;
|
|
202
|
+
content_type?: string;
|
|
203
|
+
item_id?: string;
|
|
204
|
+
};
|
|
205
|
+
sign_up: {
|
|
206
|
+
method?: string;
|
|
207
|
+
};
|
|
208
|
+
spend_virtual_currency: {
|
|
209
|
+
value: number;
|
|
210
|
+
virtual_currency_name: string;
|
|
211
|
+
item_name?: string;
|
|
212
|
+
};
|
|
213
|
+
tutorial_begin: undefined;
|
|
214
|
+
tutorial_complete: undefined;
|
|
215
|
+
unlock_achievement: {
|
|
216
|
+
achievement_id: string;
|
|
217
|
+
};
|
|
218
|
+
view_cart: {
|
|
219
|
+
currency: string;
|
|
220
|
+
value: number;
|
|
221
|
+
items: Item[];
|
|
222
|
+
};
|
|
223
|
+
view_item: {
|
|
224
|
+
currency: string;
|
|
225
|
+
value: number;
|
|
226
|
+
items: Item[];
|
|
227
|
+
};
|
|
228
|
+
view_item_list: {
|
|
229
|
+
currency: string;
|
|
230
|
+
item_list_id?: string;
|
|
231
|
+
item_list_name?: string;
|
|
232
|
+
items: Item[];
|
|
233
|
+
};
|
|
234
|
+
view_promotion: {
|
|
235
|
+
creative_name?: string;
|
|
236
|
+
creative_slot?: string;
|
|
237
|
+
promotion_id?: string;
|
|
238
|
+
promotion_name?: string;
|
|
239
|
+
items: (Item & PromotionItem)[];
|
|
240
|
+
};
|
|
241
|
+
working_lead: {
|
|
242
|
+
currency: string;
|
|
243
|
+
value: number;
|
|
244
|
+
lead_status?: string;
|
|
245
|
+
};
|
|
246
|
+
ad_impression: {
|
|
247
|
+
value?: number;
|
|
248
|
+
currency?: string;
|
|
249
|
+
ad_format?: string;
|
|
250
|
+
ad_platform?: string;
|
|
251
|
+
ad_source?: string;
|
|
252
|
+
ad_unit_name?: string;
|
|
253
|
+
};
|
|
254
|
+
app_open: undefined;
|
|
255
|
+
campaign_details: {
|
|
256
|
+
source: string;
|
|
257
|
+
medium: string;
|
|
258
|
+
campaign: string;
|
|
259
|
+
term?: string;
|
|
260
|
+
content?: string;
|
|
261
|
+
aclid?: string;
|
|
262
|
+
cp1?: string;
|
|
263
|
+
};
|
|
264
|
+
screen_view: {
|
|
265
|
+
screen_name?: string;
|
|
266
|
+
screen_class?: string;
|
|
267
|
+
};
|
|
268
|
+
view_search_results: {
|
|
269
|
+
search_term: string;
|
|
270
|
+
};
|
|
271
|
+
trial_begin: {
|
|
272
|
+
currency: string;
|
|
273
|
+
value: number;
|
|
274
|
+
};
|
|
275
|
+
subscribe: {
|
|
276
|
+
currency: string;
|
|
277
|
+
value: number;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* reference: https://developers.google.com/analytics/devguides/collection/ga4/reference/config
|
|
282
|
+
* reference: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag
|
|
283
|
+
*/
|
|
284
|
+
interface Gtag {
|
|
285
|
+
/**
|
|
286
|
+
* To disable advertising features based on third-party advertising identifiers, set
|
|
287
|
+
* allow_google_signals to false.
|
|
288
|
+
*
|
|
289
|
+
* @param allow - Whether to allow Google signals.
|
|
290
|
+
* @default true
|
|
291
|
+
*/
|
|
292
|
+
gtag(event: 'set', option: 'allow_google_signals', allow: boolean): void;
|
|
293
|
+
/**
|
|
294
|
+
* Set to false to disable advertising personalization features.
|
|
295
|
+
*
|
|
296
|
+
* @param allow - Whether to allow ad personalization signals.
|
|
297
|
+
* @default true
|
|
298
|
+
*/
|
|
299
|
+
gtag(event: 'set', option: 'allow_ad_personalization_signals', allow: boolean): void;
|
|
300
|
+
/**
|
|
301
|
+
* Used for A/B testing and content-targeted ads. Use campaign_content to differentiate ads or
|
|
302
|
+
* links that point to the same URL.
|
|
303
|
+
*/
|
|
304
|
+
gtag(event: 'set', option: 'campaign_content', content: string): void;
|
|
305
|
+
/**
|
|
306
|
+
* Used to identify which campaign this referral references. Use campaign_id to identify a
|
|
307
|
+
* specific campaign.
|
|
308
|
+
*/
|
|
309
|
+
gtag(event: 'set', option: 'campaign_id', id: string): void;
|
|
310
|
+
/** Use campaign_medium to identify a medium such as email or cost-per-click. */
|
|
311
|
+
gtag(event: 'set', option: 'campaign_medium', medium: CampaignMedium): void;
|
|
312
|
+
/**
|
|
313
|
+
* Used for keyword analysis. Use campaign_name to identify a specific product promotion or
|
|
314
|
+
* strategic campaign.
|
|
315
|
+
*/
|
|
316
|
+
gtag(event: 'set', option: 'campaign_name', name: string): void;
|
|
317
|
+
/** Use campaign_source to identify a search engine, newsletter name, or other source. */
|
|
318
|
+
gtag(event: 'set', option: 'campaign_source', source: CampaignSource): void;
|
|
319
|
+
/** Used for paid search. Use campaign_term to note the keywords for this ad. */
|
|
320
|
+
gtag(event: 'set', option: 'campaign_term', term: string): void;
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated
|
|
323
|
+
* Key Point: Use the campaign_ prefixed version of each campaign value instead of this field.
|
|
324
|
+
*/
|
|
325
|
+
gtag(event: 'set', option: 'campaign', params: Campaign): void;
|
|
326
|
+
/**
|
|
327
|
+
* Pseudonymously identifies a browser instance. By default, this value is stored as part of the
|
|
328
|
+
* first-party Analytics cookie with a two-year expiration.
|
|
329
|
+
*/
|
|
330
|
+
gtag(event: 'set', option: 'client_id', id: string): void;
|
|
331
|
+
/** example: gtag('set', 'content_group', '/news/sports'); */
|
|
332
|
+
gtag(event: 'set', option: 'content_group', group: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Specifies the domain used to store the analytics cookie.
|
|
335
|
+
* Set to 'none' to set the cookie without specifying a domain.
|
|
336
|
+
* Set to 'auto' (the default value) to set the cookie to the top level domain plus one
|
|
337
|
+
* subdomain (eTLD +1). For example if cookie_domain is set to 'auto' https://example.com would
|
|
338
|
+
* use example.com for the domain, and https://subdomain.example.com would also use example.com
|
|
339
|
+
* for the domain.
|
|
340
|
+
*
|
|
341
|
+
* @param domain - The domain used to store the analytics cookie.
|
|
342
|
+
* @default 'auto'
|
|
343
|
+
*/
|
|
344
|
+
gtag(event: 'set', option: 'cookie_domain', domain: 'none' | 'auto' | string): void;
|
|
345
|
+
/**
|
|
346
|
+
* Every time a hit is sent to Google Analytics, the cookie expiration time is updated to be the
|
|
347
|
+
* current time plus the value of the cookie_expires field. This means that if you use the default
|
|
348
|
+
* value time of two years (63072000 seconds), and a user visits your site every month, their
|
|
349
|
+
* cookie will never expire.
|
|
350
|
+
*
|
|
351
|
+
* If you set the cookie_expires time to 0 (zero) seconds, the cookie turns into a session based
|
|
352
|
+
* cookie and expires once the current browser session ends.
|
|
353
|
+
*
|
|
354
|
+
* Caution: If you set the cookie to expire too quickly, you will inflate your user count and
|
|
355
|
+
* decrease the quality of your measurement.
|
|
356
|
+
*
|
|
357
|
+
* @param expires - The number of seconds until the cookie expires.
|
|
358
|
+
* @default 63072000
|
|
359
|
+
*/
|
|
360
|
+
gtag(event: 'set', option: 'cookie_expires', expires: number): void;
|
|
361
|
+
/**
|
|
362
|
+
* Appends additional flags to the cookie when set. Flags must be separated by semicolons. See
|
|
363
|
+
* [write a new cookie](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#write_a_new_cookie) for some examples of flags to set.
|
|
364
|
+
*/
|
|
365
|
+
gtag(event: 'set', option: 'cookie_flags', flags: string): void;
|
|
366
|
+
/** Specifies the subpath used to store the analytics cookie. */
|
|
367
|
+
gtag(event: 'set', option: 'cookie_path', path: string): void;
|
|
368
|
+
/** Specifies a prefix to prepend to analytics cookie names. */
|
|
369
|
+
gtag(event: 'set', option: 'cookie_prefix', prefix: string): void;
|
|
370
|
+
/**
|
|
371
|
+
* When cookie_update is set to true, gtag.js will update cookies on each page load. This will
|
|
372
|
+
* update the cookie expiration to be set relative to the most recent visit to the site. For
|
|
373
|
+
* example, if cookie expiration is set to one week, and a user visits using the same browser
|
|
374
|
+
* every five days, the cookie expiration will be updated on each visit and will effectively
|
|
375
|
+
* never expire.
|
|
376
|
+
*
|
|
377
|
+
* When set to false, cookies are not updated on each page load. This has the effect of cookie
|
|
378
|
+
* expiration being relative to the first time a user visited the site.
|
|
379
|
+
*
|
|
380
|
+
* @param update - Whether to update the cookie on each page load.
|
|
381
|
+
* @default true
|
|
382
|
+
*/
|
|
383
|
+
gtag(event: 'set', option: 'cookie_update', update: boolean): void;
|
|
384
|
+
/**
|
|
385
|
+
* Set to true to indicate to Analytics that the referrer shouldn't be displayed as a traffic
|
|
386
|
+
* source. [Learn when to use this field](https://support.google.com/analytics/answer/10327750#set-parameter)
|
|
387
|
+
*
|
|
388
|
+
* @param ignore - Whether to ignore the referrer.
|
|
389
|
+
* @default false
|
|
390
|
+
*/
|
|
391
|
+
gtag(event: 'set', option: 'ignore_referrer', ignore: boolean): void;
|
|
392
|
+
/**
|
|
393
|
+
* Specifies the language preference of the user. Defaults to the user's navigator.language value.
|
|
394
|
+
*
|
|
395
|
+
* @param language - The language preference of the user.
|
|
396
|
+
* @default navigator.language
|
|
397
|
+
*/
|
|
398
|
+
gtag(event: 'set', option: 'language', language: string): void;
|
|
399
|
+
/**
|
|
400
|
+
* Specifies the full URL of the page. Defaults to the user's document.location value.
|
|
401
|
+
*
|
|
402
|
+
* @param location - The full URL of the page. Character limit 1000
|
|
403
|
+
* @default document.location
|
|
404
|
+
*/
|
|
405
|
+
gtag(event: 'set', option: 'page_location', location: string): void;
|
|
406
|
+
/**
|
|
407
|
+
* Specifies which referral source brought traffic to a page. This value is also used to compute
|
|
408
|
+
* the traffic source. The format of this value is a URL. Defaults to the user's document.referrer
|
|
409
|
+
* value.
|
|
410
|
+
*
|
|
411
|
+
* @param referrer - The referral source. Character limit 420
|
|
412
|
+
* @default document.referrer
|
|
413
|
+
*/
|
|
414
|
+
gtag(event: 'set', option: 'page_referrer', referrer: string): void;
|
|
415
|
+
/**
|
|
416
|
+
* The title of the page or document. Defaults to the user's document.title value.
|
|
417
|
+
*
|
|
418
|
+
* @param title - The title of the page or document. Character limit 300
|
|
419
|
+
* @default document.title
|
|
420
|
+
*/
|
|
421
|
+
gtag(event: 'set', option: 'page_title', title: string): void;
|
|
422
|
+
/**
|
|
423
|
+
* Set to false to prevent the default snippet from sending a page_view.
|
|
424
|
+
*
|
|
425
|
+
* @param send - Whether to send a page_view.
|
|
426
|
+
* @default true
|
|
427
|
+
*/
|
|
428
|
+
gtag(event: 'set', option: 'send_page_view', send: boolean): void;
|
|
429
|
+
/**
|
|
430
|
+
* Specifies the resolution of the screen. Should be two positive integers separated by an x. For
|
|
431
|
+
* example, for an 800px by 600px screen, the value would be 800x600. Calculated from the user's
|
|
432
|
+
* window.screen value.
|
|
433
|
+
*
|
|
434
|
+
* @param resolution - The resolution of the screen.
|
|
435
|
+
* @default window.screen
|
|
436
|
+
*/
|
|
437
|
+
gtag(event: 'set', option: 'screen_resolution', resolution: `${number}x${number}`): void;
|
|
438
|
+
/**
|
|
439
|
+
* Specifies a known identifier for a user provided by the site owner/library user. It must not
|
|
440
|
+
* itself be PII (personally identifiable information). The value should never be persisted in
|
|
441
|
+
* Google Analytics cookies or other Analytics provided storage.
|
|
442
|
+
*
|
|
443
|
+
* @param userId - The user ID. Character limit 256
|
|
444
|
+
*/
|
|
445
|
+
gtag(event: 'set', option: 'user_id', userId: string): void;
|
|
446
|
+
/**
|
|
447
|
+
* User properties are attributes that can be used to describe segments of your user base, such
|
|
448
|
+
* as language preference or geographic location. Up to 25 additional user properties can be set
|
|
449
|
+
* per project.
|
|
450
|
+
*
|
|
451
|
+
* @param name - The name of the user property. Character limit 24
|
|
452
|
+
* @param value - The value of the user property. Character limit 36
|
|
453
|
+
*/
|
|
454
|
+
gtag(event: 'set', option: 'user_property', properties: Record<string, string | boolean | number | null | undefined>): void;
|
|
455
|
+
/**
|
|
456
|
+
* gtag('config', ...) Set for a single stream
|
|
457
|
+
* gtag('set', ...) Set globally
|
|
458
|
+
*/
|
|
459
|
+
gtag(event: 'config', gaId: GaId, config?: Config): void;
|
|
460
|
+
gtag<T extends string>(event: 'event', eventName: T extends keyof StandardEvents ? T : string, eventParams?: T extends keyof StandardEvents ? StandardEvents[T] : Record<string, string | number | boolean | null | undefined>): void;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export { type Campaign, type CampaignMedium, type CampaignSource, type Config, type GaId, type Gtag, type GtmId, type Item, type PromotionItem, type StandardEvents, reservedEventNames, standardEventNames };
|