@callforge/tracking-client 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +18 -20
- package/dist/index.mjs +18 -20
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -83,6 +83,7 @@ Requirements:
|
|
|
83
83
|
|
|
84
84
|
How it works:
|
|
85
85
|
- Extracts the GA4 `client_id` from the `_ga` cookie and sends it to CallForge as `ga4ClientId`.
|
|
86
|
+
- Polls briefly after init to capture the cookie if Google Analytics sets it slightly later.
|
|
86
87
|
- If `ga4MeasurementId` is configured and `gtag` is available, also uses `gtag('get', measurementId, 'client_id', ...)` (with a short retry window).
|
|
87
88
|
- If `ga4ClientId` becomes available after a session is created, the client will refresh once to sync it to CallForge.
|
|
88
89
|
|
|
@@ -187,6 +188,7 @@ client.setParams({
|
|
|
187
188
|
|
|
188
189
|
Behavior:
|
|
189
190
|
- Merges with existing params (later calls override earlier values).
|
|
191
|
+
- If a session already exists (cached `sessionToken`), the client will refresh once to sync updated params server-side (best-effort).
|
|
190
192
|
- Parameters are sent with every `getSession()` API request.
|
|
191
193
|
- Persisted in localStorage alongside session data.
|
|
192
194
|
|
package/dist/index.d.mts
CHANGED
|
@@ -113,7 +113,10 @@ declare class CallForge {
|
|
|
113
113
|
*/
|
|
114
114
|
onReady(callback: ReadyCallback): void;
|
|
115
115
|
/**
|
|
116
|
-
* Set custom tracking parameters for
|
|
116
|
+
* Set custom tracking parameters for attribution.
|
|
117
|
+
*
|
|
118
|
+
* When possible, the client will also refresh the session once to sync
|
|
119
|
+
* the updated params to CallForge (so server-side events can use them).
|
|
117
120
|
*/
|
|
118
121
|
setParams(params: Record<string, string>): Promise<void>;
|
|
119
122
|
/**
|
|
@@ -142,7 +145,7 @@ declare class CallForge {
|
|
|
142
145
|
private saveToCache;
|
|
143
146
|
private formatSession;
|
|
144
147
|
private formatApiResponse;
|
|
145
|
-
private
|
|
148
|
+
private syncParamsToCallForgeIfPossible;
|
|
146
149
|
private buildUrl;
|
|
147
150
|
}
|
|
148
151
|
|
package/dist/index.d.ts
CHANGED
|
@@ -113,7 +113,10 @@ declare class CallForge {
|
|
|
113
113
|
*/
|
|
114
114
|
onReady(callback: ReadyCallback): void;
|
|
115
115
|
/**
|
|
116
|
-
* Set custom tracking parameters for
|
|
116
|
+
* Set custom tracking parameters for attribution.
|
|
117
|
+
*
|
|
118
|
+
* When possible, the client will also refresh the session once to sync
|
|
119
|
+
* the updated params to CallForge (so server-side events can use them).
|
|
117
120
|
*/
|
|
118
121
|
setParams(params: Record<string, string>): Promise<void>;
|
|
119
122
|
/**
|
|
@@ -142,7 +145,7 @@ declare class CallForge {
|
|
|
142
145
|
private saveToCache;
|
|
143
146
|
private formatSession;
|
|
144
147
|
private formatApiResponse;
|
|
145
|
-
private
|
|
148
|
+
private syncParamsToCallForgeIfPossible;
|
|
146
149
|
private buildUrl;
|
|
147
150
|
}
|
|
148
151
|
|
package/dist/index.js
CHANGED
|
@@ -210,23 +210,27 @@ var CallForge = class _CallForge {
|
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
* Set custom tracking parameters for
|
|
213
|
+
* Set custom tracking parameters for attribution.
|
|
214
|
+
*
|
|
215
|
+
* When possible, the client will also refresh the session once to sync
|
|
216
|
+
* the updated params to CallForge (so server-side events can use them).
|
|
214
217
|
*/
|
|
215
218
|
async setParams(params) {
|
|
216
219
|
this.customParams = __spreadValues(__spreadValues({}, this.customParams), params);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
} else {
|
|
228
|
-
void sync();
|
|
220
|
+
const sync = async () => {
|
|
221
|
+
try {
|
|
222
|
+
await this.syncParamsToCallForgeIfPossible();
|
|
223
|
+
} catch (e) {
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (this.sessionPromise) {
|
|
227
|
+
try {
|
|
228
|
+
await this.sessionPromise;
|
|
229
|
+
} catch (e) {
|
|
229
230
|
}
|
|
231
|
+
await sync();
|
|
232
|
+
} else {
|
|
233
|
+
await sync();
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
236
|
/**
|
|
@@ -259,7 +263,6 @@ var CallForge = class _CallForge {
|
|
|
259
263
|
});
|
|
260
264
|
}
|
|
261
265
|
startGA4ClientIdPolling() {
|
|
262
|
-
if (!this.config.ga4MeasurementId) return;
|
|
263
266
|
if (typeof window === "undefined") return;
|
|
264
267
|
if (this.customParams.ga4ClientId) return;
|
|
265
268
|
const MAX_ATTEMPTS = 20;
|
|
@@ -391,18 +394,13 @@ var CallForge = class _CallForge {
|
|
|
391
394
|
location: data.location
|
|
392
395
|
};
|
|
393
396
|
}
|
|
394
|
-
async
|
|
395
|
-
const ga4ClientId = this.customParams.ga4ClientId;
|
|
396
|
-
if (!ga4ClientId) return;
|
|
397
|
+
async syncParamsToCallForgeIfPossible() {
|
|
397
398
|
const locationId = this.getLocationId();
|
|
398
399
|
const sessionToken = this.cache.getSessionToken(locationId);
|
|
399
400
|
if (!sessionToken) return;
|
|
400
401
|
const autoParams = this.getAutoParams();
|
|
401
402
|
const cachedParams = this.cache.getParams();
|
|
402
403
|
const params = __spreadValues(__spreadValues(__spreadValues({}, autoParams), cachedParams), this.customParams);
|
|
403
|
-
if (cachedParams.ga4ClientId === params.ga4ClientId) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
404
|
const data = await this.fetchFromApi(locationId, sessionToken, params);
|
|
407
405
|
this.saveToCache(locationId, data, params);
|
|
408
406
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -186,23 +186,27 @@ var CallForge = class _CallForge {
|
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
189
|
-
* Set custom tracking parameters for
|
|
189
|
+
* Set custom tracking parameters for attribution.
|
|
190
|
+
*
|
|
191
|
+
* When possible, the client will also refresh the session once to sync
|
|
192
|
+
* the updated params to CallForge (so server-side events can use them).
|
|
190
193
|
*/
|
|
191
194
|
async setParams(params) {
|
|
192
195
|
this.customParams = __spreadValues(__spreadValues({}, this.customParams), params);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
} else {
|
|
204
|
-
void sync();
|
|
196
|
+
const sync = async () => {
|
|
197
|
+
try {
|
|
198
|
+
await this.syncParamsToCallForgeIfPossible();
|
|
199
|
+
} catch (e) {
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
if (this.sessionPromise) {
|
|
203
|
+
try {
|
|
204
|
+
await this.sessionPromise;
|
|
205
|
+
} catch (e) {
|
|
205
206
|
}
|
|
207
|
+
await sync();
|
|
208
|
+
} else {
|
|
209
|
+
await sync();
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
/**
|
|
@@ -235,7 +239,6 @@ var CallForge = class _CallForge {
|
|
|
235
239
|
});
|
|
236
240
|
}
|
|
237
241
|
startGA4ClientIdPolling() {
|
|
238
|
-
if (!this.config.ga4MeasurementId) return;
|
|
239
242
|
if (typeof window === "undefined") return;
|
|
240
243
|
if (this.customParams.ga4ClientId) return;
|
|
241
244
|
const MAX_ATTEMPTS = 20;
|
|
@@ -367,18 +370,13 @@ var CallForge = class _CallForge {
|
|
|
367
370
|
location: data.location
|
|
368
371
|
};
|
|
369
372
|
}
|
|
370
|
-
async
|
|
371
|
-
const ga4ClientId = this.customParams.ga4ClientId;
|
|
372
|
-
if (!ga4ClientId) return;
|
|
373
|
+
async syncParamsToCallForgeIfPossible() {
|
|
373
374
|
const locationId = this.getLocationId();
|
|
374
375
|
const sessionToken = this.cache.getSessionToken(locationId);
|
|
375
376
|
if (!sessionToken) return;
|
|
376
377
|
const autoParams = this.getAutoParams();
|
|
377
378
|
const cachedParams = this.cache.getParams();
|
|
378
379
|
const params = __spreadValues(__spreadValues(__spreadValues({}, autoParams), cachedParams), this.customParams);
|
|
379
|
-
if (cachedParams.ga4ClientId === params.ga4ClientId) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
380
|
const data = await this.fetchFromApi(locationId, sessionToken, params);
|
|
383
381
|
this.saveToCache(locationId, data, params);
|
|
384
382
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@callforge/tracking-client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"jsdom": "^27.4.0",
|
|
22
|
+
"tsup": "^8.0.0",
|
|
23
|
+
"typescript": "^5.3.0",
|
|
24
|
+
"vitest": "^1.6.0",
|
|
25
|
+
"@callforge/tsconfig": "0.0.0"
|
|
26
|
+
},
|
|
20
27
|
"scripts": {
|
|
21
28
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
22
29
|
"clean": "rm -rf dist",
|
|
23
30
|
"test": "vitest run",
|
|
24
31
|
"test:watch": "vitest"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@callforge/tsconfig": "workspace:*",
|
|
28
|
-
"jsdom": "^27.4.0",
|
|
29
|
-
"tsup": "^8.0.0",
|
|
30
|
-
"typescript": "^5.3.0",
|
|
31
|
-
"vitest": "^1.6.0"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|