@ht-sdks/events-sdk-js-browser 1.3.0 → 1.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 +62 -17
- package/dist/cjs/generated/version.js +1 -1
- package/dist/cjs/plugins/destinations/google-tag-manager.js +8 -21
- package/dist/cjs/plugins/destinations/google-tag-manager.js.map +1 -1
- package/dist/cjs/plugins/destinations/gtag.js +44 -0
- package/dist/cjs/plugins/destinations/gtag.js.map +1 -0
- package/dist/cjs/plugins/destinations/index.js +4 -0
- package/dist/cjs/plugins/destinations/index.js.map +1 -1
- package/dist/pkg/generated/version.js +1 -1
- package/dist/pkg/plugins/destinations/google-tag-manager.js +8 -21
- package/dist/pkg/plugins/destinations/google-tag-manager.js.map +1 -1
- package/dist/pkg/plugins/destinations/gtag.js +42 -0
- package/dist/pkg/plugins/destinations/gtag.js.map +1 -0
- package/dist/pkg/plugins/destinations/index.js +4 -0
- package/dist/pkg/plugins/destinations/index.js.map +1 -1
- package/dist/types/core/buffer/index.d.ts +1 -1
- package/dist/types/generated/version.d.ts +1 -1
- package/dist/types/plugins/destinations/google-tag-manager.d.ts +1 -5
- package/dist/types/plugins/destinations/google-tag-manager.d.ts.map +1 -1
- package/dist/types/plugins/destinations/gtag.d.ts +27 -0
- package/dist/types/plugins/destinations/gtag.d.ts.map +1 -0
- package/dist/types/plugins/destinations/index.d.ts.map +1 -1
- package/dist/umd/events.min.js +1 -1
- package/dist/umd/events.min.js.map +1 -1
- package/dist/umd/google-tag-manager.bundle.238ad1d40bdf04d984ef.js +2 -0
- package/dist/umd/google-tag-manager.bundle.238ad1d40bdf04d984ef.js.map +1 -0
- package/dist/umd/gtag.bundle.a5e7c472f1c04f2b9ebd.js +2 -0
- package/dist/umd/gtag.bundle.a5e7c472f1c04f2b9ebd.js.map +1 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/http-cookies/server-examples/node-aws-lambda.md +1 -1
- package/src/generated/version.ts +1 -1
- package/src/plugins/destinations/google-tag-manager.ts +15 -36
- package/src/plugins/destinations/gtag.ts +93 -0
- package/src/plugins/destinations/index.ts +4 -0
- package/dist/umd/google-tag-manager.bundle.c27daab560c3298c04ca.js +0 -2
- package/dist/umd/google-tag-manager.bundle.c27daab560c3298c04ca.js.map +0 -1
package/README.md
CHANGED
|
@@ -221,38 +221,82 @@ For further examples check out our [existing plugins](/packages/browser/src/plug
|
|
|
221
221
|
|
|
222
222
|
The Browser SDK supports sending events directly from the client to destinations which is useful in situations where the destination requires a client-side context in order to fully enrich and attribute events.
|
|
223
223
|
|
|
224
|
-
## Google
|
|
224
|
+
## Google Tag Manager
|
|
225
225
|
|
|
226
|
-
Google
|
|
226
|
+
The Google Tag Manager integration pushes events directly to [Google Tag Manager](https://support.google.com/tagmanager/answer/6102821?hl=en). This tag in turn can forward to a variety of other tools.
|
|
227
227
|
|
|
228
228
|
### Installation
|
|
229
229
|
|
|
230
|
-
Make sure your
|
|
230
|
+
Make sure your Google Tag Manager setup scripts are configured on your website. Our implementation expects `window.dataLayer` to be available in the global scope.
|
|
231
231
|
|
|
232
232
|
```html
|
|
233
|
-
<!-- example
|
|
234
|
-
<script
|
|
233
|
+
<!-- example Google Tag Manager script -->
|
|
234
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
235
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
236
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
237
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
238
|
+
})(window,document,'script','dataLayer','GTM-XXXXXXXX');</script>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
You can then configure the Browser SDK to send events directly to Google Tag Manager by enabling the `Google Tag Manager` destination:
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
htevents.load('WRITE_KEY', {
|
|
245
|
+
destinations: {
|
|
246
|
+
'Google Tag Manager': {},
|
|
247
|
+
},
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
View the complete plugin documentation in [`google-tag-manager.ts`](src/plugins/destinations/google-tag-manager.ts#L12)
|
|
252
|
+
|
|
253
|
+
### Usage
|
|
254
|
+
|
|
255
|
+
Once the destination is configured, all applicable `identify`, `track`, and `page` events will be sent. The integration also automatically populates the `userId` and `hightouchAnonymousId` fields.
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
htevents.track('My Event', { prop: 'abc' })
|
|
259
|
+
// This results in the following Google Tag Manager event.
|
|
260
|
+
// window.dataLayer.push({ event: 'My Event', prop: 'abc', user_id: '123', hightouch_anonymous_id: '456' })
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## gtag.js
|
|
264
|
+
|
|
265
|
+
The Google Tag (gtag.js) integration pushes events directly to [gtag.js](https://developers.google.com/tag-platform/gtagjs). This tag in turn can forward to a variety of Google products, including Google Ads, Google Analytics, Campaign Manager, Display & Video 360, and Search Ads 360.
|
|
266
|
+
|
|
267
|
+
### Installation
|
|
268
|
+
|
|
269
|
+
Make sure your gtag.js setup scripts are configured on your website. Our implementation expects the `gtag` function to be available in the global scope.
|
|
270
|
+
|
|
271
|
+
```html
|
|
272
|
+
<!-- example GA4 setup using gtag.js -->
|
|
273
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX" ></script>
|
|
235
274
|
<script>
|
|
236
|
-
window.dataLayer = window.dataLayer || []
|
|
237
|
-
function gtag() {
|
|
238
|
-
|
|
239
|
-
|
|
275
|
+
window.dataLayer = window.dataLayer || []
|
|
276
|
+
function gtag() {
|
|
277
|
+
dataLayer.push(arguments)
|
|
278
|
+
}
|
|
279
|
+
gtag('js', new Date())
|
|
280
|
+
gtag('config', 'G-XXXXXXXX')
|
|
240
281
|
</script>
|
|
241
282
|
```
|
|
242
283
|
|
|
243
|
-
You can then configure the Browser SDK to send events directly to
|
|
284
|
+
You can then configure the Browser SDK to send events directly to gtag.js by enabling the `gtag` destination:
|
|
244
285
|
|
|
245
286
|
```js
|
|
246
|
-
htevents.load(
|
|
287
|
+
htevents.load('WRITE_KEY', {
|
|
247
288
|
destinations: {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
289
|
+
gtag: {
|
|
290
|
+
// Events are only forwarded to the configured measurement IDs.
|
|
291
|
+
// For example, if you'd like to forward to GA4, you should include
|
|
292
|
+
// your GA4 measurement ID here.
|
|
293
|
+
measurementId: 'G-XXXXXXXX',
|
|
294
|
+
},
|
|
295
|
+
},
|
|
252
296
|
})
|
|
253
297
|
```
|
|
254
298
|
|
|
255
|
-
View the complete plugin documentation in [`
|
|
299
|
+
View the complete plugin documentation in [`gtag.ts`](src/plugins/destinations/gtag.ts#L11)
|
|
256
300
|
|
|
257
301
|
### Usage
|
|
258
302
|
|
|
@@ -260,7 +304,8 @@ Once the destination is configured, all applicable `identify`, `track`, and `pag
|
|
|
260
304
|
|
|
261
305
|
```js
|
|
262
306
|
htevents.track('My Event', { prop: 'abc' })
|
|
263
|
-
//
|
|
307
|
+
// This results in the following gtag call.
|
|
308
|
+
// gtag('event', 'My Event', { prop: 'abc', user_id: '123', hightouchAnonymousId: '456' })
|
|
264
309
|
```
|
|
265
310
|
|
|
266
311
|
## Custom client-side destinations
|
|
@@ -6,28 +6,15 @@ var destination_1 = require("./destination");
|
|
|
6
6
|
* https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/google-tag-manager/lib/index.js
|
|
7
7
|
*/
|
|
8
8
|
var googleTagManager = function (_a) {
|
|
9
|
-
var _b = _a.
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, (event.userId && {
|
|
14
|
-
user_id: event.userId,
|
|
9
|
+
var _b = _a.trackAllPages, trackAllPages = _b === void 0 ? false : _b, _c = _a.trackNamedPages, trackNamedPages = _c === void 0 ? true : _c, _d = _a.trackCategorizedPages, trackCategorizedPages = _d === void 0 ? true : _d;
|
|
10
|
+
var pushEvent = function (event) {
|
|
11
|
+
window.dataLayer.push(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, (event.userId && {
|
|
12
|
+
userId: event.userId,
|
|
15
13
|
})), (event.anonymousId && {
|
|
16
|
-
|
|
17
|
-
})),
|
|
18
|
-
send_to: measurementIds,
|
|
19
|
-
})), event.properties);
|
|
14
|
+
hightouchAnonymousId: event.anonymousId,
|
|
15
|
+
})), { event: event.event }), event.properties));
|
|
20
16
|
};
|
|
21
17
|
return new destination_1.Destination('Google Tag Manager', '0.0.1', {
|
|
22
|
-
identify: function (ctx) {
|
|
23
|
-
if (ctx.event.userId) {
|
|
24
|
-
measurementIds.forEach(function (measurementId) {
|
|
25
|
-
window.gtag('config', measurementId, {
|
|
26
|
-
user_id: ctx.event.userId,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
18
|
page: function (ctx) {
|
|
32
19
|
if (trackAllPages ||
|
|
33
20
|
(trackNamedPages && ctx.event.name) ||
|
|
@@ -35,11 +22,11 @@ var googleTagManager = function (_a) {
|
|
|
35
22
|
var eventName = ['Viewed', ctx.event.category, ctx.event.name, 'Page']
|
|
36
23
|
.filter(Boolean)
|
|
37
24
|
.join(' ');
|
|
38
|
-
|
|
25
|
+
pushEvent(tslib_1.__assign(tslib_1.__assign({}, ctx.event), { type: 'track', event: eventName }));
|
|
39
26
|
}
|
|
40
27
|
},
|
|
41
28
|
track: function (ctx) {
|
|
42
|
-
|
|
29
|
+
pushEvent(ctx.event);
|
|
43
30
|
},
|
|
44
31
|
});
|
|
45
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-tag-manager.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"google-tag-manager.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":";;;AAGA,6CAA2C;AAyB3C;;GAEG;AACH,IAAM,gBAAgB,GAAiD,UAAC,EAIvE;QAHC,qBAAqB,EAArB,aAAa,mBAAG,KAAK,KAAA,EACrB,uBAAsB,EAAtB,eAAe,mBAAG,IAAI,KAAA,EACtB,6BAA4B,EAA5B,qBAAqB,mBAAG,IAAI,KAAA;IAE5B,IAAM,SAAS,GAAG,UAAC,KAAqB;QACtC,MAAM,CAAC,SAAS,CAAC,IAAI,yEAChB,CAAC,KAAK,CAAC,MAAM,IAAI;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,GACC,CAAC,KAAK,CAAC,WAAW,IAAI;YACvB,oBAAoB,EAAE,KAAK,CAAC,WAAW;SACxC,CAAC,KACF,KAAK,EAAE,KAAK,CAAC,KAAK,KACf,KAAK,CAAC,UAAU,EACnB,CAAA;IACJ,CAAC,CAAA;IAED,OAAO,IAAI,yBAAW,CAAC,oBAAoB,EAAE,OAAO,EAAE;QACpD,IAAI,EAAE,UAAC,GAAY;YACjB,IACE,aAAa;gBACb,CAAC,eAAe,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBACnC,CAAC,qBAAqB,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAC7C;gBACA,IAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;qBACrE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEZ,SAAS,uCACJ,GAAG,CAAC,KAAK,KACZ,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,SAAS,IAChB,CAAA;aACH;QACH,CAAC;QAED,KAAK,EAAE,UAAC,GAAY;YAClB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,kBAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var destination_1 = require("./destination");
|
|
5
|
+
var gtag = function (_a) {
|
|
6
|
+
var _b = _a.measurementId, measurementId = _b === void 0 ? [] : _b, _c = _a.trackAllPages, trackAllPages = _c === void 0 ? false : _c, _d = _a.trackNamedPages, trackNamedPages = _d === void 0 ? true : _d, _e = _a.trackCategorizedPages, trackCategorizedPages = _e === void 0 ? true : _e;
|
|
7
|
+
var measurementIds = (Array.isArray(measurementId) ? measurementId : [measurementId]).filter(Boolean);
|
|
8
|
+
var baseEvent = function (_a) {
|
|
9
|
+
var event = _a.event;
|
|
10
|
+
return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, (event.userId && {
|
|
11
|
+
user_id: event.userId,
|
|
12
|
+
})), (event.anonymousId && {
|
|
13
|
+
hightouch_anonymous_id: event.anonymousId,
|
|
14
|
+
})), (measurementIds.length > 0 && {
|
|
15
|
+
send_to: measurementIds,
|
|
16
|
+
})), event.properties);
|
|
17
|
+
};
|
|
18
|
+
return new destination_1.Destination('gtag', '0.0.1', {
|
|
19
|
+
identify: function (ctx) {
|
|
20
|
+
if (ctx.event.userId) {
|
|
21
|
+
measurementIds.forEach(function (measurementId) {
|
|
22
|
+
window.gtag('config', measurementId, {
|
|
23
|
+
user_id: ctx.event.userId,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
page: function (ctx) {
|
|
29
|
+
if (trackAllPages ||
|
|
30
|
+
(trackNamedPages && ctx.event.name) ||
|
|
31
|
+
(trackCategorizedPages && ctx.event.category)) {
|
|
32
|
+
var eventName = ['Viewed', ctx.event.category, ctx.event.name, 'Page']
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(' ');
|
|
35
|
+
window.gtag('event', eventName, tslib_1.__assign({}, baseEvent(ctx)));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
track: function (ctx) {
|
|
39
|
+
window.gtag('event', ctx.event.event, tslib_1.__assign({}, baseEvent(ctx)));
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.default = gtag;
|
|
44
|
+
//# sourceMappingURL=gtag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtag.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/gtag.ts"],"names":[],"mappings":";;;AAEA,6CAA2C;AA8B3C,IAAM,IAAI,GAAqC,UAAC,EAK/C;QAJC,qBAAkB,EAAlB,aAAa,mBAAG,EAAE,KAAA,EAClB,qBAAqB,EAArB,aAAa,mBAAG,KAAK,KAAA,EACrB,uBAAsB,EAAtB,eAAe,mBAAG,IAAI,KAAA,EACtB,6BAA4B,EAA5B,qBAAqB,mBAAG,IAAI,KAAA;IAE5B,IAAM,cAAc,GAAG,CACrB,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAC/D,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAEjB,IAAM,SAAS,GAAG,UAAC,EAAkB;YAAhB,KAAK,WAAA;QACxB,+EACK,CAAC,KAAK,CAAC,MAAM,IAAI;YAClB,OAAO,EAAE,KAAK,CAAC,MAAM;SACtB,CAAC,GACC,CAAC,KAAK,CAAC,WAAW,IAAI;YACvB,sBAAsB,EAAE,KAAK,CAAC,WAAW;SAC1C,CAAC,GACC,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI;YAC/B,OAAO,EAAE,cAAc;SACxB,CAAC,GACC,KAAK,CAAC,UAAU,EACpB;IACH,CAAC,CAAA;IAED,OAAO,IAAI,yBAAW,CAAC,MAAM,EAAE,OAAO,EAAE;QACtC,QAAQ,EAAE,UAAC,GAAG;YACZ,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE;gBACpB,cAAc,CAAC,OAAO,CAAC,UAAC,aAAa;oBACnC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE;wBACnC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM;qBAC1B,CAAC,CAAA;gBACJ,CAAC,CAAC,CAAA;aACH;QACH,CAAC;QAED,IAAI,EAAE,UAAC,GAAG;YACR,IACE,aAAa;gBACb,CAAC,eAAe,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBACnC,CAAC,qBAAqB,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAC7C;gBACA,IAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;qBACrE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEZ,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,uBACzB,SAAS,CAAC,GAAG,CAAC,EACjB,CAAA;aACH;QACH,CAAC;QAED,KAAK,EAAE,UAAC,GAAG;YACT,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,uBAC/B,SAAS,CAAC,GAAG,CAAC,EACjB,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,kBAAe,IAAI,CAAA"}
|
|
@@ -8,6 +8,10 @@ function createDestination(name, settings) {
|
|
|
8
8
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
9
9
|
return tslib_1.__generator(this, function (_a) {
|
|
10
10
|
switch (name) {
|
|
11
|
+
case 'gtag':
|
|
12
|
+
return [2 /*return*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(/* webpackChunkName: "gtag" */ './gtag')); }).then(function (mod) {
|
|
13
|
+
return mod.default(settings);
|
|
14
|
+
})];
|
|
11
15
|
case 'Google Tag Manager':
|
|
12
16
|
return [2 /*return*/, Promise.resolve().then(function () { return tslib_1.__importStar(require(
|
|
13
17
|
/* webpackChunkName: "google-tag-manager" */ './google-tag-manager')); }).then(function (mod) { return mod.default(settings); })];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":";;;;AACA,6CAA2C;AAElC,4FAFA,yBAAW,OAEA;AAGpB,SAAsB,iBAAiB,CACrC,IAAY,EACZ,QAA6B;;;YAE7B,QAAQ,IAAI,EAAE;gBACZ,KAAK,oBAAoB;oBACvB,sBAAO;wBACL,4CAA4C,CAAC,sBAAsB,OACnE,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC,EAA5B,CAA4B,CAAC,EAAA;gBAC/C;oBACE,sBAAO,SAAS,EAAA;aACnB;;;;CACF;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":";;;;AACA,6CAA2C;AAElC,4FAFA,yBAAW,OAEA;AAGpB,SAAsB,iBAAiB,CACrC,IAAY,EACZ,QAA6B;;;YAE7B,QAAQ,IAAI,EAAE;gBACZ,KAAK,MAAM;oBACT,sBAAO,yEAAO,8BAA8B,CAAC,QAAQ,OAAE,IAAI,CAAC,UAAC,GAAG;4BAC9D,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC;wBAA5B,CAA4B,CAC7B,EAAA;gBACH,KAAK,oBAAoB;oBACvB,sBAAO;wBACL,4CAA4C,CAAC,sBAAsB,OACnE,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC,EAA5B,CAA4B,CAAC,EAAA;gBAC/C;oBACE,sBAAO,SAAS,EAAA;aACnB;;;;CACF;AAhBD,8CAgBC"}
|
|
@@ -4,28 +4,15 @@ import { Destination } from './destination';
|
|
|
4
4
|
* https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/google-tag-manager/lib/index.js
|
|
5
5
|
*/
|
|
6
6
|
var googleTagManager = function (_a) {
|
|
7
|
-
var _b = _a.
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return __assign(__assign(__assign(__assign({}, (event.userId && {
|
|
12
|
-
user_id: event.userId,
|
|
7
|
+
var _b = _a.trackAllPages, trackAllPages = _b === void 0 ? false : _b, _c = _a.trackNamedPages, trackNamedPages = _c === void 0 ? true : _c, _d = _a.trackCategorizedPages, trackCategorizedPages = _d === void 0 ? true : _d;
|
|
8
|
+
var pushEvent = function (event) {
|
|
9
|
+
window.dataLayer.push(__assign(__assign(__assign(__assign({}, (event.userId && {
|
|
10
|
+
userId: event.userId,
|
|
13
11
|
})), (event.anonymousId && {
|
|
14
|
-
|
|
15
|
-
})),
|
|
16
|
-
send_to: measurementIds,
|
|
17
|
-
})), event.properties);
|
|
12
|
+
hightouchAnonymousId: event.anonymousId,
|
|
13
|
+
})), { event: event.event }), event.properties));
|
|
18
14
|
};
|
|
19
15
|
return new Destination('Google Tag Manager', '0.0.1', {
|
|
20
|
-
identify: function (ctx) {
|
|
21
|
-
if (ctx.event.userId) {
|
|
22
|
-
measurementIds.forEach(function (measurementId) {
|
|
23
|
-
window.gtag('config', measurementId, {
|
|
24
|
-
user_id: ctx.event.userId,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
16
|
page: function (ctx) {
|
|
30
17
|
if (trackAllPages ||
|
|
31
18
|
(trackNamedPages && ctx.event.name) ||
|
|
@@ -33,11 +20,11 @@ var googleTagManager = function (_a) {
|
|
|
33
20
|
var eventName = ['Viewed', ctx.event.category, ctx.event.name, 'Page']
|
|
34
21
|
.filter(Boolean)
|
|
35
22
|
.join(' ');
|
|
36
|
-
|
|
23
|
+
pushEvent(__assign(__assign({}, ctx.event), { type: 'track', event: eventName }));
|
|
37
24
|
}
|
|
38
25
|
},
|
|
39
26
|
track: function (ctx) {
|
|
40
|
-
|
|
27
|
+
pushEvent(ctx.event);
|
|
41
28
|
},
|
|
42
29
|
});
|
|
43
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-tag-manager.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"google-tag-manager.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAyB3C;;GAEG;AACH,IAAM,gBAAgB,GAAiD,UAAC,EAIvE;QAHC,qBAAqB,EAArB,aAAa,mBAAG,KAAK,KAAA,EACrB,uBAAsB,EAAtB,eAAe,mBAAG,IAAI,KAAA,EACtB,6BAA4B,EAA5B,qBAAqB,mBAAG,IAAI,KAAA;IAE5B,IAAM,SAAS,GAAG,UAAC,KAAqB;QACtC,MAAM,CAAC,SAAS,CAAC,IAAI,yCAChB,CAAC,KAAK,CAAC,MAAM,IAAI;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,GACC,CAAC,KAAK,CAAC,WAAW,IAAI;YACvB,oBAAoB,EAAE,KAAK,CAAC,WAAW;SACxC,CAAC,KACF,KAAK,EAAE,KAAK,CAAC,KAAK,KACf,KAAK,CAAC,UAAU,EACnB,CAAA;IACJ,CAAC,CAAA;IAED,OAAO,IAAI,WAAW,CAAC,oBAAoB,EAAE,OAAO,EAAE;QACpD,IAAI,EAAE,UAAC,GAAY;YACjB,IACE,aAAa;gBACb,CAAC,eAAe,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBACnC,CAAC,qBAAqB,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAC7C;gBACA,IAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;qBACrE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEZ,SAAS,uBACJ,GAAG,CAAC,KAAK,KACZ,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,SAAS,IAChB,CAAA;aACH;QACH,CAAC;QAED,KAAK,EAAE,UAAC,GAAY;YAClB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { Destination } from './destination';
|
|
3
|
+
var gtag = function (_a) {
|
|
4
|
+
var _b = _a.measurementId, measurementId = _b === void 0 ? [] : _b, _c = _a.trackAllPages, trackAllPages = _c === void 0 ? false : _c, _d = _a.trackNamedPages, trackNamedPages = _d === void 0 ? true : _d, _e = _a.trackCategorizedPages, trackCategorizedPages = _e === void 0 ? true : _e;
|
|
5
|
+
var measurementIds = (Array.isArray(measurementId) ? measurementId : [measurementId]).filter(Boolean);
|
|
6
|
+
var baseEvent = function (_a) {
|
|
7
|
+
var event = _a.event;
|
|
8
|
+
return __assign(__assign(__assign(__assign({}, (event.userId && {
|
|
9
|
+
user_id: event.userId,
|
|
10
|
+
})), (event.anonymousId && {
|
|
11
|
+
hightouch_anonymous_id: event.anonymousId,
|
|
12
|
+
})), (measurementIds.length > 0 && {
|
|
13
|
+
send_to: measurementIds,
|
|
14
|
+
})), event.properties);
|
|
15
|
+
};
|
|
16
|
+
return new Destination('gtag', '0.0.1', {
|
|
17
|
+
identify: function (ctx) {
|
|
18
|
+
if (ctx.event.userId) {
|
|
19
|
+
measurementIds.forEach(function (measurementId) {
|
|
20
|
+
window.gtag('config', measurementId, {
|
|
21
|
+
user_id: ctx.event.userId,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
page: function (ctx) {
|
|
27
|
+
if (trackAllPages ||
|
|
28
|
+
(trackNamedPages && ctx.event.name) ||
|
|
29
|
+
(trackCategorizedPages && ctx.event.category)) {
|
|
30
|
+
var eventName = ['Viewed', ctx.event.category, ctx.event.name, 'Page']
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join(' ');
|
|
33
|
+
window.gtag('event', eventName, __assign({}, baseEvent(ctx)));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
track: function (ctx) {
|
|
37
|
+
window.gtag('event', ctx.event.event, __assign({}, baseEvent(ctx)));
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export default gtag;
|
|
42
|
+
//# sourceMappingURL=gtag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtag.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/gtag.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AA8B3C,IAAM,IAAI,GAAqC,UAAC,EAK/C;QAJC,qBAAkB,EAAlB,aAAa,mBAAG,EAAE,KAAA,EAClB,qBAAqB,EAArB,aAAa,mBAAG,KAAK,KAAA,EACrB,uBAAsB,EAAtB,eAAe,mBAAG,IAAI,KAAA,EACtB,6BAA4B,EAA5B,qBAAqB,mBAAG,IAAI,KAAA;IAE5B,IAAM,cAAc,GAAG,CACrB,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAC/D,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAEjB,IAAM,SAAS,GAAG,UAAC,EAAkB;YAAhB,KAAK,WAAA;QACxB,+CACK,CAAC,KAAK,CAAC,MAAM,IAAI;YAClB,OAAO,EAAE,KAAK,CAAC,MAAM;SACtB,CAAC,GACC,CAAC,KAAK,CAAC,WAAW,IAAI;YACvB,sBAAsB,EAAE,KAAK,CAAC,WAAW;SAC1C,CAAC,GACC,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,IAAI;YAC/B,OAAO,EAAE,cAAc;SACxB,CAAC,GACC,KAAK,CAAC,UAAU,EACpB;IACH,CAAC,CAAA;IAED,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE;QACtC,QAAQ,EAAE,UAAC,GAAG;YACZ,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE;gBACpB,cAAc,CAAC,OAAO,CAAC,UAAC,aAAa;oBACnC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,EAAE;wBACnC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM;qBAC1B,CAAC,CAAA;gBACJ,CAAC,CAAC,CAAA;aACH;QACH,CAAC;QAED,IAAI,EAAE,UAAC,GAAG;YACR,IACE,aAAa;gBACb,CAAC,eAAe,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;gBACnC,CAAC,qBAAqB,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAC7C;gBACA,IAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;qBACrE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEZ,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,eACzB,SAAS,CAAC,GAAG,CAAC,EACjB,CAAA;aACH;QACH,CAAC;QAED,KAAK,EAAE,UAAC,GAAG;YACT,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,eAC/B,SAAS,CAAC,GAAG,CAAC,EACjB,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -5,6 +5,10 @@ export function createDestination(name, settings) {
|
|
|
5
5
|
return __awaiter(this, void 0, void 0, function () {
|
|
6
6
|
return __generator(this, function (_a) {
|
|
7
7
|
switch (name) {
|
|
8
|
+
case 'gtag':
|
|
9
|
+
return [2 /*return*/, import(/* webpackChunkName: "gtag" */ './gtag').then(function (mod) {
|
|
10
|
+
return mod.default(settings);
|
|
11
|
+
})];
|
|
8
12
|
case 'Google Tag Manager':
|
|
9
13
|
return [2 /*return*/, import(
|
|
10
14
|
/* webpackChunkName: "google-tag-manager" */ './google-tag-manager').then(function (mod) { return mod.default(settings); })];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAGtB,MAAM,UAAgB,iBAAiB,CACrC,IAAY,EACZ,QAA6B;;;YAE7B,QAAQ,IAAI,EAAE;gBACZ,KAAK,oBAAoB;oBACvB,sBAAO,MAAM;wBACX,4CAA4C,CAAC,sBAAsB,CACpE,CAAC,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC,EAA5B,CAA4B,CAAC,EAAA;gBAC/C;oBACE,sBAAO,SAAS,EAAA;aACnB;;;;CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAGtB,MAAM,UAAgB,iBAAiB,CACrC,IAAY,EACZ,QAA6B;;;YAE7B,QAAQ,IAAI,EAAE;gBACZ,KAAK,MAAM;oBACT,sBAAO,MAAM,CAAC,8BAA8B,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAC,GAAG;4BAC9D,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC;wBAA5B,CAA4B,CAC7B,EAAA;gBACH,KAAK,oBAAoB;oBACvB,sBAAO,MAAM;wBACX,4CAA4C,CAAC,sBAAsB,CACpE,CAAC,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,CAAC,QAAe,CAAC,EAA5B,CAA4B,CAAC,EAAA;gBAC/C;oBACE,sBAAO,SAAS,EAAA;aACnB;;;;CACF"}
|
|
@@ -91,7 +91,7 @@ export declare class AnalyticsBuffered implements PromiseLike<[Analytics, Contex
|
|
|
91
91
|
register: (...args: import("../plugin").Plugin[]) => Promise<Context>;
|
|
92
92
|
deregister: (...args: string[]) => Promise<Context>;
|
|
93
93
|
user: () => Promise<import("../user").User>;
|
|
94
|
-
readonly VERSION = "1.3.
|
|
94
|
+
readonly VERSION = "1.3.1";
|
|
95
95
|
private _createMethod;
|
|
96
96
|
/**
|
|
97
97
|
* These are for methods that where determining when the method gets "flushed" is not important.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.3.
|
|
1
|
+
export declare const version = "1.3.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { DestinationFactory } from './types';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
|
-
|
|
4
|
+
dataLayer: Array<any>;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
type GoogleTagManagerSettings = {
|
|
8
|
-
/**
|
|
9
|
-
* The Google measurement ID(s) to send events to (GA4, Ads)
|
|
10
|
-
*/
|
|
11
|
-
measurementId?: string | string[];
|
|
12
8
|
/**
|
|
13
9
|
* If a `Viewed Page` event should be sent for all `htevents.page` calls
|
|
14
10
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-tag-manager.d.ts","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-tag-manager.d.ts","sourceRoot":"","sources":["../../../../src/plugins/destinations/google-tag-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;KACtB;CACF;AAED,KAAK,wBAAwB,GAAG;IAC9B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,gBAAgB,EAAE,kBAAkB,CAAC,wBAAwB,CAyClE,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DestinationFactory } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
gtag: Function;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
type GtagSettings = {
|
|
8
|
+
/**
|
|
9
|
+
* The Google measurement ID(s) to send events to (GA4, Ads)
|
|
10
|
+
*/
|
|
11
|
+
measurementId?: string | string[];
|
|
12
|
+
/**
|
|
13
|
+
* If a `Viewed Page` event should be sent for all `htevents.page` calls
|
|
14
|
+
*/
|
|
15
|
+
trackAllPages?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If a `Viewed <name> Page` event should be sent for `htevents.page('Name')` calls
|
|
18
|
+
*/
|
|
19
|
+
trackNamedPages?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* If a `Viewed <category> <name> Page` event should be sent for `htevents.page('Category', 'Name')` calls
|
|
22
|
+
*/
|
|
23
|
+
trackCategorizedPages?: boolean;
|
|
24
|
+
};
|
|
25
|
+
declare const gtag: DestinationFactory<GtagSettings>;
|
|
26
|
+
export default gtag;
|
|
27
|
+
//# sourceMappingURL=gtag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gtag.d.ts","sourceRoot":"","sources":["../../../../src/plugins/destinations/gtag.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGjD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,EAAE,QAAQ,CAAA;KACf;CACF;AAED,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEjC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAED,QAAA,MAAM,IAAI,EAAE,kBAAkB,CAAC,YAAY,CA0D1C,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/destinations/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAalC"}
|