@callforge/tracking-client 0.3.0 → 0.3.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.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Lightweight client library for the CallForge tracking API. Handles location-aware phone number assignment with aggressive caching and preload optimization.
4
4
 
5
+ **v0.3.0** - Added automatic GA4 integration for sending call events to Google Analytics 4.
6
+
5
7
  ## Installation
6
8
 
7
9
  ```bash
@@ -51,7 +53,37 @@ client.onReady((session) => {
51
53
  });
52
54
  ```
53
55
 
54
- ### 3. Track conversion parameters (optional)
56
+ ### 3. GA4 Integration (automatic)
57
+
58
+ The client automatically captures the GA4 client ID from the `_ga` cookie and associates it with the tracking session. This enables CallForge to send call events (phone call, conversion, billable conversion) to your Google Analytics 4 property.
59
+
60
+ **Requirements:**
61
+ 1. Google Analytics 4 must be installed on your site
62
+ 2. Configure GA4 credentials in CallForge dashboard (Categories → Edit → GA4 tab)
63
+
64
+ **How it works:**
65
+ - On initialization, the client checks for the `_ga` cookie
66
+ - If not found immediately (GA4 script may load async), polls every 500ms for up to 10 seconds
67
+ - Once found, extracts the client ID and sends it to CallForge via `setParams()`
68
+ - If session already exists, uses PATCH to update with the GA4 client ID
69
+
70
+ **Manual override:** If you need to pass a custom GA4 client ID:
71
+
72
+ ```typescript
73
+ client.setParams({
74
+ ga4ClientId: '1234567890.1234567890',
75
+ });
76
+ ```
77
+
78
+ **Extract GA4 client ID yourself:**
79
+
80
+ ```typescript
81
+ import { getGA4ClientId } from '@callforge/tracking-client';
82
+
83
+ const clientId = getGA4ClientId(); // "1234567890.1234567890" or null
84
+ ```
85
+
86
+ ### 4. Track conversion parameters (optional)
55
87
 
56
88
  The client automatically captures ad platform click IDs from the URL:
57
89
 
@@ -150,19 +182,35 @@ const html = getPreloadSnippet({
150
182
  });
151
183
  ```
152
184
 
185
+ ### `getGA4ClientId()`
186
+
187
+ Extract the GA4 client ID from the `_ga` cookie.
188
+
189
+ ```typescript
190
+ import { getGA4ClientId } from '@callforge/tracking-client';
191
+
192
+ const clientId = getGA4ClientId();
193
+ // Returns: "1234567890.1234567890" or null if cookie not found
194
+ ```
195
+
196
+ **Cookie format:** `GA1.1.1234567890.1234567890`
197
+
198
+ The client ID is the last two dot-separated segments (timestamp.random).
199
+
153
200
  ## Tracking Parameters
154
201
 
155
202
  ### Auto-Capture
156
203
 
157
- The client automatically extracts these parameters from the URL on first visit:
204
+ The client automatically extracts these parameters:
158
205
 
159
- | Parameter | Source |
160
- |-----------|--------|
161
- | `gclid` | Google Ads Click ID |
162
- | `gbraid` | Google app-to-web (iOS 14+) |
163
- | `wbraid` | Google web-to-app |
164
- | `msclkid` | Microsoft/Bing Ads |
165
- | `fbclid` | Facebook/Meta Ads |
206
+ | Parameter | Source | Capture Method |
207
+ |-----------|--------|----------------|
208
+ | `gclid` | Google Ads Click ID | URL query param |
209
+ | `gbraid` | Google app-to-web (iOS 14+) | URL query param |
210
+ | `wbraid` | Google web-to-app | URL query param |
211
+ | `msclkid` | Microsoft/Bing Ads | URL query param |
212
+ | `fbclid` | Facebook/Meta Ads | URL query param |
213
+ | `ga4ClientId` | Google Analytics 4 | `_ga` cookie (polled) |
166
214
 
167
215
  ### Persistence
168
216
 
@@ -214,21 +262,53 @@ import type {
214
262
  TrackingParams,
215
263
  ReadyCallback,
216
264
  } from '@callforge/tracking-client';
265
+
266
+ import { getGA4ClientId } from '@callforge/tracking-client';
217
267
  ```
218
268
 
219
269
  ### TrackingParams
220
270
 
221
271
  ```typescript
222
272
  interface TrackingParams {
223
- gclid?: string; // Google Ads Click ID
224
- gbraid?: string; // Google app-to-web (iOS 14+)
225
- wbraid?: string; // Google web-to-app
226
- msclkid?: string; // Microsoft/Bing Ads
227
- fbclid?: string; // Facebook/Meta Ads
273
+ gclid?: string; // Google Ads Click ID
274
+ gbraid?: string; // Google app-to-web (iOS 14+)
275
+ wbraid?: string; // Google web-to-app
276
+ msclkid?: string; // Microsoft/Bing Ads
277
+ fbclid?: string; // Facebook/Meta Ads
278
+ ga4ClientId?: string; // Google Analytics 4 Client ID (auto-captured from _ga cookie)
228
279
  [key: string]: string | undefined; // Custom params
229
280
  }
230
281
  ```
231
282
 
283
+ ## GA4 Events
284
+
285
+ When GA4 is configured for a category, CallForge sends these events to Google Analytics 4 via the Measurement Protocol:
286
+
287
+ | Event Name | When Sent | Description |
288
+ |------------|-----------|-------------|
289
+ | `phone_call` | Call initiated | A phone call was placed to the tracking number |
290
+ | `call_conversion` | Call qualified | The call met conversion criteria (e.g., duration threshold) |
291
+ | `call_conversion_billable` | Call billable | The call was both qualified AND billable |
292
+
293
+ **Event Parameters:**
294
+
295
+ All events include:
296
+ - `session_id` - CallForge session ID
297
+ - `phone_number` - Tracking number dialed
298
+ - `category` - Category slug
299
+
300
+ `call_conversion` and `call_conversion_billable` also include:
301
+ - `call_duration` - Call duration in seconds
302
+ - `buyer` - Buyer the call was routed to (if applicable)
303
+
304
+ **Setup:**
305
+ 1. In Google Analytics 4, go to Admin → Data Streams → your web stream
306
+ 2. Copy the **Measurement ID** (e.g., `G-XXXXXXXXXX`)
307
+ 3. Go to Admin → Data Streams → Measurement Protocol API secrets → Create
308
+ 4. Copy the **API Secret**
309
+ 5. In CallForge dashboard: Categories → Edit category → GA4 tab
310
+ 6. Enable GA4, paste Measurement ID and API Secret, save
311
+
232
312
  ## Environment URLs
233
313
 
234
314
  | Environment | Endpoint |
package/dist/index.d.mts CHANGED
@@ -72,6 +72,12 @@ declare global {
72
72
  }
73
73
  }
74
74
 
75
+ /**
76
+ * Extract GA4 client_id from the _ga cookie.
77
+ * Cookie format: GA1.1.1234567890.1234567890
78
+ * Client ID is the last two segments: 1234567890.1234567890
79
+ */
80
+ declare function getGA4ClientId(): string | null;
75
81
  declare class CallForge {
76
82
  private readonly config;
77
83
  private readonly cache;
@@ -141,4 +147,4 @@ declare class CallForge {
141
147
  */
142
148
  declare function getPreloadSnippet(config: CallForgeConfig): string;
143
149
 
144
- export { CallForge, type CallForgeConfig, type ReadyCallback, type TrackingLocation, type TrackingParams, type TrackingSession, getPreloadSnippet };
150
+ export { CallForge, type CallForgeConfig, type ReadyCallback, type TrackingLocation, type TrackingParams, type TrackingSession, getGA4ClientId, getPreloadSnippet };
package/dist/index.d.ts CHANGED
@@ -72,6 +72,12 @@ declare global {
72
72
  }
73
73
  }
74
74
 
75
+ /**
76
+ * Extract GA4 client_id from the _ga cookie.
77
+ * Cookie format: GA1.1.1234567890.1234567890
78
+ * Client ID is the last two segments: 1234567890.1234567890
79
+ */
80
+ declare function getGA4ClientId(): string | null;
75
81
  declare class CallForge {
76
82
  private readonly config;
77
83
  private readonly cache;
@@ -141,4 +147,4 @@ declare class CallForge {
141
147
  */
142
148
  declare function getPreloadSnippet(config: CallForgeConfig): string;
143
149
 
144
- export { CallForge, type CallForgeConfig, type ReadyCallback, type TrackingLocation, type TrackingParams, type TrackingSession, getPreloadSnippet };
150
+ export { CallForge, type CallForgeConfig, type ReadyCallback, type TrackingLocation, type TrackingParams, type TrackingSession, getGA4ClientId, getPreloadSnippet };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
35
35
  var index_exports = {};
36
36
  __export(index_exports, {
37
37
  CallForge: () => CallForge,
38
+ getGA4ClientId: () => getGA4ClientId,
38
39
  getPreloadSnippet: () => getPreloadSnippet
39
40
  });
40
41
  module.exports = __toCommonJS(index_exports);
@@ -404,5 +405,6 @@ window.__cfTracking=fetch(url,{credentials:'omit'}).then(function(r){return r.js
404
405
  // Annotate the CommonJS export names for ESM import in node:
405
406
  0 && (module.exports = {
406
407
  CallForge,
408
+ getGA4ClientId,
407
409
  getPreloadSnippet
408
410
  });
package/dist/index.mjs CHANGED
@@ -379,5 +379,6 @@ window.__cfTracking=fetch(url,{credentials:'omit'}).then(function(r){return r.js
379
379
  }
380
380
  export {
381
381
  CallForge,
382
+ getGA4ClientId,
382
383
  getPreloadSnippet
383
384
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@callforge/tracking-client",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",