@formo/analytics 1.28.6 → 1.29.1

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.
@@ -54,9 +54,10 @@ import { logger } from "../logger";
54
54
  import mergeDeepRight from "../ramda/mergeDeepRight";
55
55
  import { session } from "../storage";
56
56
  import { version } from "../version";
57
- import { CHANNEL, VERSION, PAGE_PROPERTIES_EXCLUDED_FIELDS } from "./constants";
57
+ import { CHANNEL, CLICK_ID_PARAMS, PAGE_PROPERTIES_EXCLUDED_FIELDS, VERSION, } from "./constants";
58
58
  import { generateAnonymousId } from "./utils";
59
59
  import { detectBrowser } from "../browser/browsers";
60
+ var ISO_3166_ALPHA_2_REGEX = /^[A-Z]{2}$/;
60
61
  var EventFactory = /** @class */ (function () {
61
62
  function EventFactory(options) {
62
63
  var _this = this;
@@ -81,6 +82,15 @@ var EventFactory = /** @class */ (function () {
81
82
  catch (_a) { }
82
83
  return result;
83
84
  };
85
+ this.extractClickIdParameters = function (urlObj) {
86
+ var result = {};
87
+ for (var _i = 0, CLICK_ID_PARAMS_1 = CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_1.length; _i++) {
88
+ var param = CLICK_ID_PARAMS_1[_i];
89
+ var value = urlObj.searchParams.get(param);
90
+ result[param] = value ? value.trim() : "";
91
+ }
92
+ return result;
93
+ };
84
94
  this.extractReferralParameter = function (urlObj) {
85
95
  var _a, _b, _c;
86
96
  // Strategy: Check query params first, then check path pattern if configured
@@ -113,25 +123,23 @@ var EventFactory = /** @class */ (function () {
113
123
  };
114
124
  this.getTrafficSources = function (url) {
115
125
  var urlObj = new URL(url);
116
- var contextTrafficSources = __assign(__assign({}, _this.extractUTMParameters(url)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
126
+ var contextTrafficSources = __assign(__assign(__assign({}, _this.extractUTMParameters(url)), _this.extractClickIdParameters(urlObj)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
117
127
  var storedTrafficSources = session().get(SESSION_TRAFFIC_SOURCE_KEY) || {};
118
- var finalTrafficSources = {
119
- ref: contextTrafficSources.ref || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.ref) || "",
120
- referrer: contextTrafficSources.referrer || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.referrer) || "",
121
- utm_campaign: contextTrafficSources.utm_campaign ||
128
+ var mergedClickIds = {};
129
+ for (var _i = 0, CLICK_ID_PARAMS_2 = CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_2.length; _i++) {
130
+ var p = CLICK_ID_PARAMS_2[_i];
131
+ mergedClickIds[p] =
132
+ contextTrafficSources[p] || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources[p]) || "";
133
+ }
134
+ var finalTrafficSources = __assign({ ref: contextTrafficSources.ref || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.ref) || "", referrer: contextTrafficSources.referrer || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.referrer) || "", utm_campaign: contextTrafficSources.utm_campaign ||
122
135
  (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_campaign) ||
123
- "",
124
- utm_content: contextTrafficSources.utm_content ||
136
+ "", utm_content: contextTrafficSources.utm_content ||
125
137
  (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_content) ||
126
- "",
127
- utm_medium: contextTrafficSources.utm_medium ||
138
+ "", utm_medium: contextTrafficSources.utm_medium ||
128
139
  (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_medium) ||
129
- "",
130
- utm_source: contextTrafficSources.utm_source ||
140
+ "", utm_source: contextTrafficSources.utm_source ||
131
141
  (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_source) ||
132
- "",
133
- utm_term: contextTrafficSources.utm_term || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_term) || "",
134
- };
142
+ "", utm_term: contextTrafficSources.utm_term || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_term) || "" }, mergedClickIds);
135
143
  // Store to session
136
144
  var sessionStoredTrafficSources = Object.keys(finalTrafficSources).reduce(function (res, key) {
137
145
  var value = finalTrafficSources[key];
@@ -217,9 +225,14 @@ var EventFactory = /** @class */ (function () {
217
225
  EventFactory.prototype.getLocation = function () {
218
226
  try {
219
227
  var timezone = this.getTimezone();
220
- if (timezone in COUNTRY_LIST)
221
- return COUNTRY_LIST[timezone];
222
- return timezone;
228
+ if (!timezone)
229
+ return "";
230
+ var mapped = COUNTRY_LIST[timezone];
231
+ // Only emit ISO-3166 alpha-2. Anything else (including the raw
232
+ // timezone string) is treated as unknown.
233
+ return typeof mapped === "string" && ISO_3166_ALPHA_2_REGEX.test(mapped)
234
+ ? mapped
235
+ : "";
223
236
  }
224
237
  catch (error) {
225
238
  logger.error("Error resolving location:", error);
@@ -1,11 +1,17 @@
1
1
  declare const CHANNEL = "web";
2
2
  declare const VERSION = "0";
3
+ /**
4
+ * Paid-attribution click IDs captured from the landing-page URL and persisted
5
+ * across the session alongside UTM parameters. Keep the ClickIdParameters type
6
+ * in src/types/events.ts derived from this array.
7
+ */
8
+ declare const CLICK_ID_PARAMS: readonly ["gclid", "gad_source", "fbclid", "msclkid", "twclid", "li_fat_id", "rdt_cid", "ttclid"];
3
9
  /**
4
10
  * Fields that should be excluded from page event properties parsing
5
11
  * These are either:
6
- * - Already captured in event context (UTM params, referral params)
12
+ * - Already captured in event context (UTM params, referral params, click IDs)
7
13
  * - Semantic event properties that should not be overridden by URL params
8
14
  */
9
15
  declare const PAGE_PROPERTIES_EXCLUDED_FIELDS: Set<string>;
10
- export { CHANNEL, VERSION, PAGE_PROPERTIES_EXCLUDED_FIELDS };
16
+ export { CHANNEL, VERSION, CLICK_ID_PARAMS, PAGE_PROPERTIES_EXCLUDED_FIELDS };
11
17
  //# sourceMappingURL=constants.d.ts.map
@@ -1,12 +1,36 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
1
10
  var CHANNEL = "web";
2
11
  var VERSION = "0";
12
+ /**
13
+ * Paid-attribution click IDs captured from the landing-page URL and persisted
14
+ * across the session alongside UTM parameters. Keep the ClickIdParameters type
15
+ * in src/types/events.ts derived from this array.
16
+ */
17
+ var CLICK_ID_PARAMS = [
18
+ "gclid", // Google Ads
19
+ "gad_source", // Google Ads (newer)
20
+ "fbclid", // Meta (Facebook/Instagram)
21
+ "msclkid", // Microsoft Ads (Bing)
22
+ "twclid", // Twitter/X Ads
23
+ "li_fat_id", // LinkedIn Ads
24
+ "rdt_cid", // Reddit Ads
25
+ "ttclid", // TikTok Ads
26
+ ];
3
27
  /**
4
28
  * Fields that should be excluded from page event properties parsing
5
29
  * These are either:
6
- * - Already captured in event context (UTM params, referral params)
30
+ * - Already captured in event context (UTM params, referral params, click IDs)
7
31
  * - Semantic event properties that should not be overridden by URL params
8
32
  */
9
- var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
33
+ var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set(__spreadArray(__spreadArray([
10
34
  // Context fields (already captured in event context)
11
35
  'utm_source',
12
36
  'utm_medium',
@@ -16,7 +40,8 @@ var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
16
40
  'ref',
17
41
  'referral',
18
42
  'refcode',
19
- 'referrer',
43
+ 'referrer'
44
+ ], CLICK_ID_PARAMS, true), [
20
45
  // Semantic event properties (should not be overridden by URL params)
21
46
  'category',
22
47
  'name',
@@ -24,6 +49,6 @@ var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
24
49
  'path',
25
50
  'hash',
26
51
  'query',
27
- ]);
28
- export { CHANNEL, VERSION, PAGE_PROPERTIES_EXCLUDED_FIELDS };
52
+ ], false));
53
+ export { CHANNEL, VERSION, CLICK_ID_PARAMS, PAGE_PROPERTIES_EXCLUDED_FIELDS };
29
54
  //# sourceMappingURL=constants.js.map
@@ -1,6 +1,7 @@
1
1
  import { UUID } from "crypto";
2
2
  import { Address, ChainID, Nullable } from "./base";
3
3
  import { TEventChannel, TEventType } from "../constants";
4
+ import { CLICK_ID_PARAMS } from "../event/constants";
4
5
  export type AnonymousID = UUID;
5
6
  export interface ICommonProperties {
6
7
  anonymous_id: AnonymousID;
@@ -21,7 +22,10 @@ export type UTMParameters = {
21
22
  utm_term: string;
22
23
  utm_content: string;
23
24
  };
24
- export type ITrafficSource = UTMParameters & {
25
+ export type ClickIdParameters = {
26
+ [K in (typeof CLICK_ID_PARAMS)[number]]: string;
27
+ };
28
+ export type ITrafficSource = UTMParameters & ClickIdParameters & {
25
29
  ref: string;
26
30
  referrer: string;
27
31
  };
@@ -1,2 +1,2 @@
1
- export declare const version = "1.28.6";
1
+ export declare const version = "1.29.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // This file is auto-generated by scripts/update-version.js during npm version
2
2
  // Do not edit manually - it will be overwritten
3
- export var version = '1.28.6';
3
+ export var version = '1.29.1';
4
4
  //# sourceMappingURL=version.js.map