@walkeros/web-destination-gtag 0.0.7
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 +330 -0
- package/dist/examples/index.d.mts +60 -0
- package/dist/examples/index.d.ts +60 -0
- package/dist/examples/index.js +279 -0
- package/dist/examples/index.mjs +257 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.es5.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# @walkeros/web-destination-gtag
|
|
2
|
+
|
|
3
|
+
Unified Google destination for walkerOS supporting Google Analytics 4 (GA4),
|
|
4
|
+
Google Ads, and Google Tag Manager (GTM) through a single gtag implementation.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **Unified Configuration**: Configure GA4, Google Ads, and GTM in a single
|
|
9
|
+
destination
|
|
10
|
+
- **Shared Script Loading**: Efficient gtag script loading shared across all
|
|
11
|
+
Google tools
|
|
12
|
+
- **Tool-Specific Mappings**: Individual mapping configurations for each Google
|
|
13
|
+
tool
|
|
14
|
+
- **TypeScript Support**: Full type safety with strict typing
|
|
15
|
+
- **Flexible Usage**: Use one, two, or all three Google tools as needed
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @walkeros/web-destination-gtag
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Basic Usage
|
|
24
|
+
|
|
25
|
+
### Single Tool (GA4 Only)
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
29
|
+
|
|
30
|
+
const destination = destinationGtag({
|
|
31
|
+
settings: {
|
|
32
|
+
ga4: {
|
|
33
|
+
measurementId: 'G-XXXXXXXXXX',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Multiple Tools
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
43
|
+
|
|
44
|
+
const destination = destinationGtag({
|
|
45
|
+
settings: {
|
|
46
|
+
ga4: {
|
|
47
|
+
measurementId: 'G-XXXXXXXXXX',
|
|
48
|
+
debug: true,
|
|
49
|
+
pageview: false,
|
|
50
|
+
},
|
|
51
|
+
ads: {
|
|
52
|
+
conversionId: 'AW-XXXXXXXXX',
|
|
53
|
+
currency: 'EUR',
|
|
54
|
+
},
|
|
55
|
+
gtm: {
|
|
56
|
+
containerId: 'GTM-XXXXXXX',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### With Collector
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { collector } from '@walkeros/collector';
|
|
66
|
+
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
67
|
+
|
|
68
|
+
const instance = collector({
|
|
69
|
+
destinations: [
|
|
70
|
+
destinationGtag({
|
|
71
|
+
settings: {
|
|
72
|
+
ga4: { measurementId: 'G-XXXXXXXXXX' },
|
|
73
|
+
ads: { conversionId: 'AW-XXXXXXXXX' },
|
|
74
|
+
gtm: { containerId: 'GTM-XXXXXXX' },
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Configuration
|
|
82
|
+
|
|
83
|
+
### GA4 Settings
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
interface GA4Settings {
|
|
87
|
+
measurementId: string; // Required: GA4 Measurement ID
|
|
88
|
+
debug?: boolean; // Enable debug mode
|
|
89
|
+
include?: Include; // Data groups to include
|
|
90
|
+
pageview?: boolean; // Send automatic pageviews (default: true)
|
|
91
|
+
server_container_url?: string; // Server-side GTM URL
|
|
92
|
+
snakeCase?: boolean; // Convert event names to snake_case (default: true)
|
|
93
|
+
transport_url?: string; // Custom transport URL
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Google Ads Settings
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface AdsSettings {
|
|
101
|
+
conversionId: string; // Required: Google Ads Conversion ID
|
|
102
|
+
currency?: string; // Default currency (default: 'EUR')
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### GTM Settings
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
interface GTMSettings {
|
|
110
|
+
containerId: string; // Required: GTM Container ID
|
|
111
|
+
dataLayer?: string; // Custom dataLayer name (default: 'dataLayer')
|
|
112
|
+
domain?: string; // Custom GTM domain
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Mapping
|
|
117
|
+
|
|
118
|
+
Each tool supports individual mapping configurations:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
const mapping = {
|
|
122
|
+
order: {
|
|
123
|
+
complete: {
|
|
124
|
+
name: 'purchase',
|
|
125
|
+
settings: {
|
|
126
|
+
ga4: {
|
|
127
|
+
include: ['data', 'context'],
|
|
128
|
+
},
|
|
129
|
+
ads: {
|
|
130
|
+
conversionId: 'abcxyz',
|
|
131
|
+
},
|
|
132
|
+
gtm: {}, // Uses 'purchase' as event name
|
|
133
|
+
},
|
|
134
|
+
data: {
|
|
135
|
+
map: {
|
|
136
|
+
transaction_id: 'data.id',
|
|
137
|
+
value: 'data.total',
|
|
138
|
+
currency: 'data.currency',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### GA4-Specific Mapping
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
settings: {
|
|
150
|
+
ga4: {
|
|
151
|
+
include: ['data', 'context', 'user'], // Data groups to include
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Google Ads Conversion Mapping
|
|
157
|
+
|
|
158
|
+
For Google Ads, specify the conversion label in the `settings.ads.label` field:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
{
|
|
162
|
+
name: 'purchase', // GA4/GTM event name
|
|
163
|
+
settings: {
|
|
164
|
+
ads: {
|
|
165
|
+
label: 'CONVERSION_LABEL', // This becomes AW-XXXXXXXXX/CONVERSION_LABEL
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### GTM DataLayer Mapping
|
|
172
|
+
|
|
173
|
+
GTM receives the full event data and pushes to the configured dataLayer:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
settings: {
|
|
177
|
+
gtm: {}, // Uses default dataLayer behavior
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Examples
|
|
182
|
+
|
|
183
|
+
### E-commerce Purchase
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
187
|
+
|
|
188
|
+
const destination = destinationGtag({
|
|
189
|
+
settings: {
|
|
190
|
+
ga4: { measurementId: 'G-XXXXXXXXXX' },
|
|
191
|
+
ads: { conversionId: 'AW-XXXXXXXXX' },
|
|
192
|
+
},
|
|
193
|
+
mapping: {
|
|
194
|
+
order: {
|
|
195
|
+
complete: {
|
|
196
|
+
name: 'purchase',
|
|
197
|
+
settings: {
|
|
198
|
+
ga4: { include: ['data'] },
|
|
199
|
+
ads: {
|
|
200
|
+
label: 'PURCHASE_LABEL', // Specify conversion label
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
data: {
|
|
204
|
+
map: {
|
|
205
|
+
transaction_id: 'data.id',
|
|
206
|
+
value: 'data.total',
|
|
207
|
+
currency: 'data.currency',
|
|
208
|
+
items: {
|
|
209
|
+
loop: [
|
|
210
|
+
'nested',
|
|
211
|
+
{
|
|
212
|
+
condition: (entity) => entity.type === 'product',
|
|
213
|
+
map: {
|
|
214
|
+
item_id: 'data.id',
|
|
215
|
+
item_name: 'data.name',
|
|
216
|
+
quantity: 'data.quantity',
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Custom Event with All Tools
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
const customEventMapping = {
|
|
233
|
+
product: {
|
|
234
|
+
view: {
|
|
235
|
+
name: 'view_item',
|
|
236
|
+
settings: {
|
|
237
|
+
ga4: { include: ['data', 'context'] },
|
|
238
|
+
ads: {}, // No conversion tracking for product views
|
|
239
|
+
gtm: {}, // Send to GTM dataLayer
|
|
240
|
+
},
|
|
241
|
+
data: {
|
|
242
|
+
map: {
|
|
243
|
+
item_id: 'data.id',
|
|
244
|
+
item_name: 'data.name',
|
|
245
|
+
item_category: 'data.category',
|
|
246
|
+
value: 'data.price',
|
|
247
|
+
currency: 'data.currency',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## TypeScript
|
|
256
|
+
|
|
257
|
+
Full TypeScript support with strict typing:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
import type { DestinationGtag } from '@walkeros/web-destination-gtag';
|
|
261
|
+
|
|
262
|
+
// Type-safe configuration
|
|
263
|
+
const config: DestinationGtag.Config = {
|
|
264
|
+
settings: {
|
|
265
|
+
ga4: {
|
|
266
|
+
measurementId: 'G-XXXXXXXXXX',
|
|
267
|
+
debug: true,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// Type-safe mapping rules
|
|
273
|
+
const rules: DestinationGtag.Rules = {
|
|
274
|
+
order: {
|
|
275
|
+
complete: {
|
|
276
|
+
name: 'purchase',
|
|
277
|
+
settings: {
|
|
278
|
+
ga4: { include: ['data'] },
|
|
279
|
+
},
|
|
280
|
+
data: {
|
|
281
|
+
map: {
|
|
282
|
+
transaction_id: 'data.id',
|
|
283
|
+
value: 'data.total',
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Best Practices
|
|
292
|
+
|
|
293
|
+
1. **Use Combined Configuration**: When using multiple Google tools, configure
|
|
294
|
+
them in a single destination for better performance and maintenance.
|
|
295
|
+
|
|
296
|
+
2. **Tool-Specific Mappings**: Use tool-specific mapping settings to customize
|
|
297
|
+
behavior for each Google product.
|
|
298
|
+
|
|
299
|
+
3. **Conversion Labels**: For Google Ads, use descriptive conversion labels in
|
|
300
|
+
the mapping `name` field.
|
|
301
|
+
|
|
302
|
+
4. **Data Inclusion**: Use GA4's `include` setting to control which data groups
|
|
303
|
+
are sent to minimize payload size.
|
|
304
|
+
|
|
305
|
+
5. **Debug Mode**: Enable GA4 debug mode during development to verify event
|
|
306
|
+
tracking.
|
|
307
|
+
|
|
308
|
+
## Troubleshooting
|
|
309
|
+
|
|
310
|
+
**Events not appearing in GA4:**
|
|
311
|
+
|
|
312
|
+
- Verify the measurement ID is correct
|
|
313
|
+
- Check that events are being triggered
|
|
314
|
+
- Enable debug mode to see events in GA4 DebugView
|
|
315
|
+
|
|
316
|
+
**Google Ads conversions not tracking:**
|
|
317
|
+
|
|
318
|
+
- Ensure conversion ID and labels are correctly configured
|
|
319
|
+
- Verify the `settings.ads.label` field contains the correct conversion label
|
|
320
|
+
- Check that the conversion action is set up in Google Ads
|
|
321
|
+
|
|
322
|
+
**GTM events not appearing:**
|
|
323
|
+
|
|
324
|
+
- Verify the container ID is correct
|
|
325
|
+
- Check the dataLayer name matches your GTM configuration
|
|
326
|
+
- Use GTM Preview mode to debug event flow
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
+
|
|
3
|
+
declare function ga4Purchase$1(): unknown[];
|
|
4
|
+
declare function ga4AddToCart$1(): unknown[];
|
|
5
|
+
declare function adsConversion$1(): unknown[];
|
|
6
|
+
declare function gtmEvent(): Record<string, unknown>;
|
|
7
|
+
|
|
8
|
+
declare const events_gtmEvent: typeof gtmEvent;
|
|
9
|
+
declare namespace events {
|
|
10
|
+
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
gtag?: Gtag.Gtag;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
interface AdsMapping {
|
|
20
|
+
label?: string;
|
|
21
|
+
}
|
|
22
|
+
interface Mapping {
|
|
23
|
+
ga4?: GA4Mapping;
|
|
24
|
+
ads?: AdsMapping;
|
|
25
|
+
gtm?: GTMMapping;
|
|
26
|
+
}
|
|
27
|
+
interface GA4Mapping {
|
|
28
|
+
include?: Include;
|
|
29
|
+
}
|
|
30
|
+
interface GTMMapping {
|
|
31
|
+
}
|
|
32
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
33
|
+
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
34
|
+
|
|
35
|
+
declare const ga4Purchase: Rule;
|
|
36
|
+
declare const ga4AddToCart: Rule;
|
|
37
|
+
declare const adsConversion: Rule;
|
|
38
|
+
declare const gtmProductView: Rule;
|
|
39
|
+
declare const combinedPurchase: Rule;
|
|
40
|
+
declare const config: {
|
|
41
|
+
order: {
|
|
42
|
+
complete: Rule;
|
|
43
|
+
};
|
|
44
|
+
product: {
|
|
45
|
+
add: Rule;
|
|
46
|
+
view: Rule;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
declare const mapping_adsConversion: typeof adsConversion;
|
|
51
|
+
declare const mapping_combinedPurchase: typeof combinedPurchase;
|
|
52
|
+
declare const mapping_config: typeof config;
|
|
53
|
+
declare const mapping_ga4AddToCart: typeof ga4AddToCart;
|
|
54
|
+
declare const mapping_ga4Purchase: typeof ga4Purchase;
|
|
55
|
+
declare const mapping_gtmProductView: typeof gtmProductView;
|
|
56
|
+
declare namespace mapping {
|
|
57
|
+
export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { events, mapping };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
+
|
|
3
|
+
declare function ga4Purchase$1(): unknown[];
|
|
4
|
+
declare function ga4AddToCart$1(): unknown[];
|
|
5
|
+
declare function adsConversion$1(): unknown[];
|
|
6
|
+
declare function gtmEvent(): Record<string, unknown>;
|
|
7
|
+
|
|
8
|
+
declare const events_gtmEvent: typeof gtmEvent;
|
|
9
|
+
declare namespace events {
|
|
10
|
+
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
gtag?: Gtag.Gtag;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
interface AdsMapping {
|
|
20
|
+
label?: string;
|
|
21
|
+
}
|
|
22
|
+
interface Mapping {
|
|
23
|
+
ga4?: GA4Mapping;
|
|
24
|
+
ads?: AdsMapping;
|
|
25
|
+
gtm?: GTMMapping;
|
|
26
|
+
}
|
|
27
|
+
interface GA4Mapping {
|
|
28
|
+
include?: Include;
|
|
29
|
+
}
|
|
30
|
+
interface GTMMapping {
|
|
31
|
+
}
|
|
32
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
33
|
+
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
34
|
+
|
|
35
|
+
declare const ga4Purchase: Rule;
|
|
36
|
+
declare const ga4AddToCart: Rule;
|
|
37
|
+
declare const adsConversion: Rule;
|
|
38
|
+
declare const gtmProductView: Rule;
|
|
39
|
+
declare const combinedPurchase: Rule;
|
|
40
|
+
declare const config: {
|
|
41
|
+
order: {
|
|
42
|
+
complete: Rule;
|
|
43
|
+
};
|
|
44
|
+
product: {
|
|
45
|
+
add: Rule;
|
|
46
|
+
view: Rule;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
declare const mapping_adsConversion: typeof adsConversion;
|
|
51
|
+
declare const mapping_combinedPurchase: typeof combinedPurchase;
|
|
52
|
+
declare const mapping_config: typeof config;
|
|
53
|
+
declare const mapping_ga4AddToCart: typeof ga4AddToCart;
|
|
54
|
+
declare const mapping_ga4Purchase: typeof ga4Purchase;
|
|
55
|
+
declare const mapping_gtmProductView: typeof gtmProductView;
|
|
56
|
+
declare namespace mapping {
|
|
57
|
+
export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { events, mapping };
|