@formo/analytics 1.28.6 → 1.29.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/dist/cjs/src/FormoAnalytics.d.ts +2 -0
- package/dist/cjs/src/FormoAnalytics.js +5 -4
- package/dist/cjs/src/constants/base.d.ts +0 -1
- package/dist/cjs/src/constants/base.js +1 -2
- package/dist/cjs/src/event/EventFactory.d.ts +1 -0
- package/dist/cjs/src/event/EventFactory.js +21 -14
- package/dist/cjs/src/event/constants.d.ts +8 -2
- package/dist/cjs/src/event/constants.js +31 -5
- package/dist/cjs/src/types/events.d.ts +5 -1
- package/dist/cjs/src/version.d.ts +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +2 -0
- package/dist/esm/src/FormoAnalytics.js +6 -5
- package/dist/esm/src/constants/base.d.ts +0 -1
- package/dist/esm/src/constants/base.js +0 -1
- package/dist/esm/src/event/EventFactory.d.ts +1 -0
- package/dist/esm/src/event/EventFactory.js +22 -15
- package/dist/esm/src/event/constants.d.ts +8 -2
- package/dist/esm/src/event/constants.js +30 -5
- package/dist/esm/src/types/events.d.ts +5 -1
- package/dist/esm/src/version.d.ts +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +13 -13
|
@@ -52,6 +52,8 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
52
52
|
private isEvmDisabled;
|
|
53
53
|
/** Instance-level flag so multiple SDK instances don't interfere. */
|
|
54
54
|
private crossSubdomainCookies;
|
|
55
|
+
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
56
|
+
private _currentUrl;
|
|
55
57
|
config: Config;
|
|
56
58
|
currentChainId?: ChainID;
|
|
57
59
|
currentAddress?: Address;
|
|
@@ -122,6 +122,8 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
122
122
|
* When true, all EIP-1193/EIP-6963 detection and wrapping is skipped.
|
|
123
123
|
*/
|
|
124
124
|
this.isEvmDisabled = false;
|
|
125
|
+
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
126
|
+
this._currentUrl = "";
|
|
125
127
|
this.currentUserId = "";
|
|
126
128
|
this.config = {
|
|
127
129
|
writeKey: writeKey,
|
|
@@ -188,6 +190,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
188
190
|
if (options.solana) {
|
|
189
191
|
this.solanaManager = new SolanaManager_1.SolanaManager(this, options.solana);
|
|
190
192
|
}
|
|
193
|
+
this._currentUrl = window.location.href;
|
|
191
194
|
this.trackPageHit();
|
|
192
195
|
this.trackPageHits();
|
|
193
196
|
}
|
|
@@ -1440,11 +1443,9 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1440
1443
|
};
|
|
1441
1444
|
FormoAnalytics.prototype.onLocationChange = function () {
|
|
1442
1445
|
return __awaiter(this, void 0, void 0, function () {
|
|
1443
|
-
var currentUrl;
|
|
1444
1446
|
return __generator(this, function (_a) {
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
(0, storage_1.cookie)().set(constants_1.SESSION_CURRENT_URL_KEY, window.location.href);
|
|
1447
|
+
if (this._currentUrl !== window.location.href) {
|
|
1448
|
+
this._currentUrl = window.location.href;
|
|
1448
1449
|
this.trackPageHit();
|
|
1449
1450
|
}
|
|
1450
1451
|
return [2 /*return*/];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
2
|
-
export declare const SESSION_CURRENT_URL_KEY = "analytics-current-url";
|
|
3
2
|
export declare const SESSION_USER_ID_KEY = "user-id";
|
|
4
3
|
export declare const LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
5
4
|
export declare const CONSENT_OPT_OUT_KEY = "opt-out-tracking";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BLOCKED_ADDRESSES = exports.DEAD_ADDRESS = exports.ZERO_ADDRESS = exports.DEFAULT_PROVIDER_ICON = exports.CONSENT_OPT_OUT_KEY = exports.LOCAL_ANONYMOUS_ID_KEY = exports.SESSION_USER_ID_KEY = exports.
|
|
3
|
+
exports.BLOCKED_ADDRESSES = exports.DEAD_ADDRESS = exports.ZERO_ADDRESS = exports.DEFAULT_PROVIDER_ICON = exports.CONSENT_OPT_OUT_KEY = exports.LOCAL_ANONYMOUS_ID_KEY = exports.SESSION_USER_ID_KEY = exports.SESSION_TRAFFIC_SOURCE_KEY = void 0;
|
|
4
4
|
exports.SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
5
5
|
// SESSION_WALLET_DETECTED_KEY and SESSION_WALLET_IDENTIFIED_KEY
|
|
6
6
|
// are now defined in src/session/index.ts
|
|
7
|
-
exports.SESSION_CURRENT_URL_KEY = "analytics-current-url";
|
|
8
7
|
exports.SESSION_USER_ID_KEY = "user-id";
|
|
9
8
|
exports.LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
10
9
|
// Consent management keys
|
|
@@ -17,6 +17,7 @@ declare class EventFactory implements IEventFactory {
|
|
|
17
17
|
private getLanguage;
|
|
18
18
|
private getLibraryVersion;
|
|
19
19
|
private extractUTMParameters;
|
|
20
|
+
private extractClickIdParameters;
|
|
20
21
|
private extractReferralParameter;
|
|
21
22
|
private getTrafficSources;
|
|
22
23
|
private getScreen;
|
|
@@ -87,6 +87,15 @@ var EventFactory = /** @class */ (function () {
|
|
|
87
87
|
catch (_a) { }
|
|
88
88
|
return result;
|
|
89
89
|
};
|
|
90
|
+
this.extractClickIdParameters = function (urlObj) {
|
|
91
|
+
var result = {};
|
|
92
|
+
for (var _i = 0, CLICK_ID_PARAMS_1 = constants_2.CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_1.length; _i++) {
|
|
93
|
+
var param = CLICK_ID_PARAMS_1[_i];
|
|
94
|
+
var value = urlObj.searchParams.get(param);
|
|
95
|
+
result[param] = value ? value.trim() : "";
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
90
99
|
this.extractReferralParameter = function (urlObj) {
|
|
91
100
|
var _a, _b, _c;
|
|
92
101
|
// Strategy: Check query params first, then check path pattern if configured
|
|
@@ -119,25 +128,23 @@ var EventFactory = /** @class */ (function () {
|
|
|
119
128
|
};
|
|
120
129
|
this.getTrafficSources = function (url) {
|
|
121
130
|
var urlObj = new URL(url);
|
|
122
|
-
var contextTrafficSources = __assign(__assign({}, _this.extractUTMParameters(url)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
|
|
131
|
+
var contextTrafficSources = __assign(__assign(__assign({}, _this.extractUTMParameters(url)), _this.extractClickIdParameters(urlObj)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
|
|
123
132
|
var storedTrafficSources = (0, storage_1.session)().get(constants_1.SESSION_TRAFFIC_SOURCE_KEY) || {};
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
var mergedClickIds = {};
|
|
134
|
+
for (var _i = 0, CLICK_ID_PARAMS_2 = constants_2.CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_2.length; _i++) {
|
|
135
|
+
var p = CLICK_ID_PARAMS_2[_i];
|
|
136
|
+
mergedClickIds[p] =
|
|
137
|
+
contextTrafficSources[p] || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources[p]) || "";
|
|
138
|
+
}
|
|
139
|
+
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 ||
|
|
128
140
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_campaign) ||
|
|
129
|
-
"",
|
|
130
|
-
utm_content: contextTrafficSources.utm_content ||
|
|
141
|
+
"", utm_content: contextTrafficSources.utm_content ||
|
|
131
142
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_content) ||
|
|
132
|
-
"",
|
|
133
|
-
utm_medium: contextTrafficSources.utm_medium ||
|
|
143
|
+
"", utm_medium: contextTrafficSources.utm_medium ||
|
|
134
144
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_medium) ||
|
|
135
|
-
"",
|
|
136
|
-
utm_source: contextTrafficSources.utm_source ||
|
|
145
|
+
"", utm_source: contextTrafficSources.utm_source ||
|
|
137
146
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_source) ||
|
|
138
|
-
"",
|
|
139
|
-
utm_term: contextTrafficSources.utm_term || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_term) || "",
|
|
140
|
-
};
|
|
147
|
+
"", utm_term: contextTrafficSources.utm_term || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_term) || "" }, mergedClickIds);
|
|
141
148
|
// Store to session
|
|
142
149
|
var sessionStoredTrafficSources = Object.keys(finalTrafficSources).reduce(function (res, key) {
|
|
143
150
|
var value = finalTrafficSources[key];
|
|
@@ -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,17 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PAGE_PROPERTIES_EXCLUDED_FIELDS = exports.VERSION = exports.CHANNEL = void 0;
|
|
12
|
+
exports.PAGE_PROPERTIES_EXCLUDED_FIELDS = exports.CLICK_ID_PARAMS = exports.VERSION = exports.CHANNEL = void 0;
|
|
4
13
|
var CHANNEL = "web";
|
|
5
14
|
exports.CHANNEL = CHANNEL;
|
|
6
15
|
var VERSION = "0";
|
|
7
16
|
exports.VERSION = VERSION;
|
|
17
|
+
/**
|
|
18
|
+
* Paid-attribution click IDs captured from the landing-page URL and persisted
|
|
19
|
+
* across the session alongside UTM parameters. Keep the ClickIdParameters type
|
|
20
|
+
* in src/types/events.ts derived from this array.
|
|
21
|
+
*/
|
|
22
|
+
var CLICK_ID_PARAMS = [
|
|
23
|
+
"gclid", // Google Ads
|
|
24
|
+
"gad_source", // Google Ads (newer)
|
|
25
|
+
"fbclid", // Meta (Facebook/Instagram)
|
|
26
|
+
"msclkid", // Microsoft Ads (Bing)
|
|
27
|
+
"twclid", // Twitter/X Ads
|
|
28
|
+
"li_fat_id", // LinkedIn Ads
|
|
29
|
+
"rdt_cid", // Reddit Ads
|
|
30
|
+
"ttclid", // TikTok Ads
|
|
31
|
+
];
|
|
32
|
+
exports.CLICK_ID_PARAMS = CLICK_ID_PARAMS;
|
|
8
33
|
/**
|
|
9
34
|
* Fields that should be excluded from page event properties parsing
|
|
10
35
|
* These are either:
|
|
11
|
-
* - Already captured in event context (UTM params, referral params)
|
|
36
|
+
* - Already captured in event context (UTM params, referral params, click IDs)
|
|
12
37
|
* - Semantic event properties that should not be overridden by URL params
|
|
13
38
|
*/
|
|
14
|
-
var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
|
|
39
|
+
var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set(__spreadArray(__spreadArray([
|
|
15
40
|
// Context fields (already captured in event context)
|
|
16
41
|
'utm_source',
|
|
17
42
|
'utm_medium',
|
|
@@ -21,7 +46,8 @@ var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
|
|
|
21
46
|
'ref',
|
|
22
47
|
'referral',
|
|
23
48
|
'refcode',
|
|
24
|
-
'referrer'
|
|
49
|
+
'referrer'
|
|
50
|
+
], CLICK_ID_PARAMS, true), [
|
|
25
51
|
// Semantic event properties (should not be overridden by URL params)
|
|
26
52
|
'category',
|
|
27
53
|
'name',
|
|
@@ -29,6 +55,6 @@ var PAGE_PROPERTIES_EXCLUDED_FIELDS = new Set([
|
|
|
29
55
|
'path',
|
|
30
56
|
'hash',
|
|
31
57
|
'query',
|
|
32
|
-
]);
|
|
58
|
+
], false));
|
|
33
59
|
exports.PAGE_PROPERTIES_EXCLUDED_FIELDS = PAGE_PROPERTIES_EXCLUDED_FIELDS;
|
|
34
60
|
//# 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
|
|
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.
|
|
1
|
+
export declare const version = "1.29.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/cjs/src/version.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.version = void 0;
|
|
4
4
|
// This file is auto-generated by scripts/update-version.js during npm version
|
|
5
5
|
// Do not edit manually - it will be overwritten
|
|
6
|
-
exports.version = '1.
|
|
6
|
+
exports.version = '1.29.0';
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -52,6 +52,8 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
52
52
|
private isEvmDisabled;
|
|
53
53
|
/** Instance-level flag so multiple SDK instances don't interfere. */
|
|
54
54
|
private crossSubdomainCookies;
|
|
55
|
+
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
56
|
+
private _currentUrl;
|
|
55
57
|
config: Config;
|
|
56
58
|
currentChainId?: ChainID;
|
|
57
59
|
currentAddress?: Address;
|
|
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
55
55
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
56
|
};
|
|
57
57
|
import { createStore } from "mipd";
|
|
58
|
-
import { EVENTS_API_HOST, EventType, LOCAL_ANONYMOUS_ID_KEY,
|
|
58
|
+
import { EVENTS_API_HOST, EventType, LOCAL_ANONYMOUS_ID_KEY, SESSION_USER_ID_KEY, CONSENT_OPT_OUT_KEY, } from "./constants";
|
|
59
59
|
import { cookie, initStorageManager } from "./storage";
|
|
60
60
|
import { getIdentityCookieDomain } from "./storage/cookiePolicy";
|
|
61
61
|
import { EventManager } from "./event";
|
|
@@ -119,6 +119,8 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
119
119
|
* When true, all EIP-1193/EIP-6963 detection and wrapping is skipped.
|
|
120
120
|
*/
|
|
121
121
|
this.isEvmDisabled = false;
|
|
122
|
+
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
123
|
+
this._currentUrl = "";
|
|
122
124
|
this.currentUserId = "";
|
|
123
125
|
this.config = {
|
|
124
126
|
writeKey: writeKey,
|
|
@@ -185,6 +187,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
185
187
|
if (options.solana) {
|
|
186
188
|
this.solanaManager = new SolanaManager(this, options.solana);
|
|
187
189
|
}
|
|
190
|
+
this._currentUrl = window.location.href;
|
|
188
191
|
this.trackPageHit();
|
|
189
192
|
this.trackPageHits();
|
|
190
193
|
}
|
|
@@ -1437,11 +1440,9 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1437
1440
|
};
|
|
1438
1441
|
FormoAnalytics.prototype.onLocationChange = function () {
|
|
1439
1442
|
return __awaiter(this, void 0, void 0, function () {
|
|
1440
|
-
var currentUrl;
|
|
1441
1443
|
return __generator(this, function (_a) {
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
cookie().set(SESSION_CURRENT_URL_KEY, window.location.href);
|
|
1444
|
+
if (this._currentUrl !== window.location.href) {
|
|
1445
|
+
this._currentUrl = window.location.href;
|
|
1445
1446
|
this.trackPageHit();
|
|
1446
1447
|
}
|
|
1447
1448
|
return [2 /*return*/];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
2
|
-
export declare const SESSION_CURRENT_URL_KEY = "analytics-current-url";
|
|
3
2
|
export declare const SESSION_USER_ID_KEY = "user-id";
|
|
4
3
|
export declare const LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
5
4
|
export declare const CONSENT_OPT_OUT_KEY = "opt-out-tracking";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export var SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
2
2
|
// SESSION_WALLET_DETECTED_KEY and SESSION_WALLET_IDENTIFIED_KEY
|
|
3
3
|
// are now defined in src/session/index.ts
|
|
4
|
-
export var SESSION_CURRENT_URL_KEY = "analytics-current-url";
|
|
5
4
|
export var SESSION_USER_ID_KEY = "user-id";
|
|
6
5
|
export var LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
7
6
|
// Consent management keys
|
|
@@ -17,6 +17,7 @@ declare class EventFactory implements IEventFactory {
|
|
|
17
17
|
private getLanguage;
|
|
18
18
|
private getLibraryVersion;
|
|
19
19
|
private extractUTMParameters;
|
|
20
|
+
private extractClickIdParameters;
|
|
20
21
|
private extractReferralParameter;
|
|
21
22
|
private getTrafficSources;
|
|
22
23
|
private getScreen;
|
|
@@ -54,7 +54,7 @@ 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,
|
|
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
60
|
var EventFactory = /** @class */ (function () {
|
|
@@ -81,6 +81,15 @@ var EventFactory = /** @class */ (function () {
|
|
|
81
81
|
catch (_a) { }
|
|
82
82
|
return result;
|
|
83
83
|
};
|
|
84
|
+
this.extractClickIdParameters = function (urlObj) {
|
|
85
|
+
var result = {};
|
|
86
|
+
for (var _i = 0, CLICK_ID_PARAMS_1 = CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_1.length; _i++) {
|
|
87
|
+
var param = CLICK_ID_PARAMS_1[_i];
|
|
88
|
+
var value = urlObj.searchParams.get(param);
|
|
89
|
+
result[param] = value ? value.trim() : "";
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
84
93
|
this.extractReferralParameter = function (urlObj) {
|
|
85
94
|
var _a, _b, _c;
|
|
86
95
|
// Strategy: Check query params first, then check path pattern if configured
|
|
@@ -113,25 +122,23 @@ var EventFactory = /** @class */ (function () {
|
|
|
113
122
|
};
|
|
114
123
|
this.getTrafficSources = function (url) {
|
|
115
124
|
var urlObj = new URL(url);
|
|
116
|
-
var contextTrafficSources = __assign(__assign({}, _this.extractUTMParameters(url)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
|
|
125
|
+
var contextTrafficSources = __assign(__assign(__assign({}, _this.extractUTMParameters(url)), _this.extractClickIdParameters(urlObj)), { ref: _this.extractReferralParameter(urlObj), referrer: document.referrer });
|
|
117
126
|
var storedTrafficSources = session().get(SESSION_TRAFFIC_SOURCE_KEY) || {};
|
|
118
|
-
var
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
var mergedClickIds = {};
|
|
128
|
+
for (var _i = 0, CLICK_ID_PARAMS_2 = CLICK_ID_PARAMS; _i < CLICK_ID_PARAMS_2.length; _i++) {
|
|
129
|
+
var p = CLICK_ID_PARAMS_2[_i];
|
|
130
|
+
mergedClickIds[p] =
|
|
131
|
+
contextTrafficSources[p] || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources[p]) || "";
|
|
132
|
+
}
|
|
133
|
+
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
134
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_campaign) ||
|
|
123
|
-
"",
|
|
124
|
-
utm_content: contextTrafficSources.utm_content ||
|
|
135
|
+
"", utm_content: contextTrafficSources.utm_content ||
|
|
125
136
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_content) ||
|
|
126
|
-
"",
|
|
127
|
-
utm_medium: contextTrafficSources.utm_medium ||
|
|
137
|
+
"", utm_medium: contextTrafficSources.utm_medium ||
|
|
128
138
|
(storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_medium) ||
|
|
129
|
-
"",
|
|
130
|
-
utm_source: contextTrafficSources.utm_source ||
|
|
139
|
+
"", utm_source: contextTrafficSources.utm_source ||
|
|
131
140
|
(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
|
-
};
|
|
141
|
+
"", utm_term: contextTrafficSources.utm_term || (storedTrafficSources === null || storedTrafficSources === void 0 ? void 0 : storedTrafficSources.utm_term) || "" }, mergedClickIds);
|
|
135
142
|
// Store to session
|
|
136
143
|
var sessionStoredTrafficSources = Object.keys(finalTrafficSources).reduce(function (res, key) {
|
|
137
144
|
var value = finalTrafficSources[key];
|
|
@@ -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
|
|
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.
|
|
1
|
+
export declare const version = "1.29.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/esm/src/version.js
CHANGED