gtm-event-tracker
Advanced tools
Comparing version 1.7.0-beta.13 to 1.7.0-beta.14
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function y(e={}){var t;const o=console;let r=(t=e.logger)!=null?t:o;function c(){return r}function n(i){r=i}return{getLogger:c,setLogger:n}}const l=y(),{setLogger:v}=l,{getLogger:w}=l;class g extends Error{constructor(t){super(t),this.name="Warning"}}class h extends Error{constructor(t){super(t),this.name="InvalidConfiguration"}}function x(){throw new h("You've called configure function without a configuration object.")}function P(e){const t=Object.entries(e),o=([c,n])=>n!=null,r=t.filter(o);return Object.fromEntries(r)}function m(){const e=t();function t(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function o(){return e}function r(n){const i=P(n);Object.assign(e,i)}function c(n){Boolean(n)||x(),r(n)}return{get:o,defaults:t,configure:c}}const f=m(),{configure:b}=f;function E(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return e.getLogger?e.getLogger():w()}function r({type:n}){const i=()=>t().debugAll,u=()=>t().debugContext,a=()=>t().debugEvents,s=p=>i()||p();return new Map([["event",s(a)],["context-created",s(u)],["context-updated",s(u)]]).get(n)}function c(n){const i=o();r(n)&&i.log(n)}return{log:c}}const d=E();function C(e){const{contextName:t,properties:o}=e;d.log({type:"context-created",contextName:t,properties:o})}function L(e){const{contextName:t,currentProps:o,newProps:r}=e;d.log({type:"context-updated",contextName:t,previousProperties:o,currentProperties:r})}function T(e={},t={}){const o={options:{...t},value:{...e}};function r(){return o.value}function c(i){const u={...i};o.value=u}function n(i){const u=r(),a={...i};L({contextName:o.options.name,currentProps:u,newProps:a}),c(a)}return C({contextName:o.options.name,properties:r()}),{context:o,setProps:n}}function N(){throw new g(`Triggering events is not possible on server-side. | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function y(n={}){var t;const o=console;let r=(t=n.logger)!=null?t:o;function c(){return r}function e(i){r=i}return{getLogger:c,setLogger:e}}const l=y(),{setLogger:v}=l,{getLogger:w}=l;class g extends Error{constructor(t){super(t),this.name="Warning"}}class x extends Error{constructor(t){super(t),this.name="InvalidConfiguration"}}function h(){throw new x("You've called configure function without a configuration object.")}function m(n){const t=Object.entries(n),o=([c,e])=>e!=null,r=t.filter(o);return Object.fromEntries(r)}function P(){const n=t();function t(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function o(){return n}function r(e){const i=m(e);Object.assign(n,i)}function c(e){Boolean(e)||h(),r(e)}return{get:o,defaults:t,configure:c}}const f=P(),{configure:b}=f;function E(n={}){function t(){var e;return(e=n.configurations)!=null?e:f.get()}function o(){return n.getLogger?n.getLogger():w()}function r({type:e}){const i=()=>t().debugAll,u=()=>t().debugContext,a=()=>t().debugEvents,s=p=>i()||p();return new Map([["event",s(a)],["context-created",s(u)],["context-updated",s(u)]]).get(e)}function c(e){const i=o();r(e)&&i.log(e)}return{log:c}}const d=E();function C(n){const{contextName:t,properties:o}=n;d.log({type:"context-created",contextName:t,properties:o})}function L(n){const{contextName:t,currentProps:o,newProps:r}=n;d.log({type:"context-updated",contextName:t,previousProperties:o,currentProperties:r})}function N(n={},t={}){const o={options:{...t},value:{...n}};function r(){return o.value}function c(i){const u=a=>{const s={...a};o.value=s};if(typeof i=="function"){const a=o.value,s=i(a);return u(s)}u(i)}function e(i){const u=r(),a={...i};L({contextName:o.options.name,currentProps:u,newProps:a}),c(a)}return C({contextName:o.options.name,properties:r()}),{context:o,setProps:e}}function T(){throw new g(`Triggering events is not possible on server-side. | ||
@@ -9,3 +9,3 @@ Make sure to only trigger events after your app is running on the client-side.`)}function k(){throw new g(`The targetProperty is not defined. | ||
Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.`)}function j(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return t().targetProperty()}function r(n){c(),o().push(n)}function c(){const n=()=>typeof window=="undefined",i=()=>Boolean(o()),u=()=>Array.isArray(o());n()?N():i()?u()||M():k()}return{addEvent:r}}const I=j();function A(e){d.log({type:"event",properties:e})}function O({context:e}){function t(r){const c={...e.value,...r};I.addEvent(c),A(c)}function o(r){return c=>{t({...e.value,...r,...c})}}return{trackEvent:t,partialTrackEvent:o}}exports.configure=b,exports.createTrackerContext=T,exports.setLogger=v,exports.withTrackerContext=O; | ||
Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.`)}function j(n={}){function t(){var e;return(e=n.configurations)!=null?e:f.get()}function o(){return t().targetProperty()}function r(e){c(),o().push(e)}function c(){const e=()=>typeof window=="undefined",i=()=>Boolean(o()),u=()=>Array.isArray(o());e()?T():i()?u()||M():k()}return{addEvent:r}}const I=j();function A(n){const{properties:t,contextName:o}=n;d.log({type:"event",properties:t,contextName:o})}function O({context:n}){function t(r){const c={...n.value,...r},e=n.options.name;I.addEvent(c),A({properties:c,contextName:e})}function o(r){return c=>{t({...n.value,...r,...c})}}return{trackEvent:t,partialTrackEvent:o}}exports.configure=b,exports.createTrackerContext=N,exports.setLogger=v,exports.withTrackerContext=O; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
function y(e={}){var t;const o=console;let r=(t=e.logger)!=null?t:o;function c(){return r}function n(i){r=i}return{getLogger:c,setLogger:n}}const l=y(),{setLogger:v}=l,{getLogger:w}=l;class g extends Error{constructor(t){super(t),this.name="Warning"}}class h extends Error{constructor(t){super(t),this.name="InvalidConfiguration"}}function x(){throw new h("You've called configure function without a configuration object.")}function m(e){const t=Object.entries(e),o=([c,n])=>n!=null,r=t.filter(o);return Object.fromEntries(r)}function P(){const e=t();function t(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function o(){return e}function r(n){const i=m(n);Object.assign(e,i)}function c(n){Boolean(n)||x(),r(n)}return{get:o,defaults:t,configure:c}}const f=P(),{configure:E}=f;function b(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return e.getLogger?e.getLogger():w()}function r({type:n}){const i=()=>t().debugAll,u=()=>t().debugContext,a=()=>t().debugEvents,s=p=>i()||p();return new Map([["event",s(a)],["context-created",s(u)],["context-updated",s(u)]]).get(n)}function c(n){const i=o();r(n)&&i.log(n)}return{log:c}}const d=b();function L(e){const{contextName:t,properties:o}=e;d.log({type:"context-created",contextName:t,properties:o})}function C(e){const{contextName:t,currentProps:o,newProps:r}=e;d.log({type:"context-updated",contextName:t,previousProperties:o,currentProperties:r})}function N(e={},t={}){const o={options:{...t},value:{...e}};function r(){return o.value}function c(i){const u={...i};o.value=u}function n(i){const u=r(),a={...i};C({contextName:o.options.name,currentProps:u,newProps:a}),c(a)}return L({contextName:o.options.name,properties:r()}),{context:o,setProps:n}}function T(){throw new g(`Triggering events is not possible on server-side. | ||
function y(e={}){var t;const o=console;let r=(t=e.logger)!=null?t:o;function c(){return r}function n(i){r=i}return{getLogger:c,setLogger:n}}const d=y(),{setLogger:v}=d,{getLogger:w}=d;class g extends Error{constructor(t){super(t),this.name="Warning"}}class x extends Error{constructor(t){super(t),this.name="InvalidConfiguration"}}function h(){throw new x("You've called configure function without a configuration object.")}function m(e){const t=Object.entries(e),o=([c,n])=>n!=null,r=t.filter(o);return Object.fromEntries(r)}function P(){const e=t();function t(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function o(){return e}function r(n){const i=m(n);Object.assign(e,i)}function c(n){Boolean(n)||h(),r(n)}return{get:o,defaults:t,configure:c}}const f=P(),{configure:E}=f;function b(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return e.getLogger?e.getLogger():w()}function r({type:n}){const i=()=>t().debugAll,u=()=>t().debugContext,a=()=>t().debugEvents,s=l=>i()||l();return new Map([["event",s(a)],["context-created",s(u)],["context-updated",s(u)]]).get(n)}function c(n){const i=o();r(n)&&i.log(n)}return{log:c}}const p=b();function L(e){const{contextName:t,properties:o}=e;p.log({type:"context-created",contextName:t,properties:o})}function N(e){const{contextName:t,currentProps:o,newProps:r}=e;p.log({type:"context-updated",contextName:t,previousProperties:o,currentProperties:r})}function C(e={},t={}){const o={options:{...t},value:{...e}};function r(){return o.value}function c(i){const u=a=>{const s={...a};o.value=s};if(typeof i=="function"){const a=o.value,s=i(a);return u(s)}u(i)}function n(i){const u=r(),a={...i};N({contextName:o.options.name,currentProps:u,newProps:a}),c(a)}return L({contextName:o.options.name,properties:r()}),{context:o,setProps:n}}function T(){throw new g(`Triggering events is not possible on server-side. | ||
@@ -9,3 +9,3 @@ Make sure to only trigger events after your app is running on the client-side.`)}function M(){throw new g(`The targetProperty is not defined. | ||
Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.`)}function I(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return t().targetProperty()}function r(n){c(),o().push(n)}function c(){const n=()=>typeof window=="undefined",i=()=>Boolean(o()),u=()=>Array.isArray(o());n()?T():i()?u()||k():M()}return{addEvent:r}}const j=I();function A(e){d.log({type:"event",properties:e})}function O({context:e}){function t(r){const c={...e.value,...r};j.addEvent(c),A(c)}function o(r){return c=>{t({...e.value,...r,...c})}}return{trackEvent:t,partialTrackEvent:o}}export{E as configure,N as createTrackerContext,v as setLogger,O as withTrackerContext}; | ||
Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.`)}function I(e={}){function t(){var n;return(n=e.configurations)!=null?n:f.get()}function o(){return t().targetProperty()}function r(n){c(),o().push(n)}function c(){const n=()=>typeof window=="undefined",i=()=>Boolean(o()),u=()=>Array.isArray(o());n()?T():i()?u()||k():M()}return{addEvent:r}}const j=I();function A(e){const{properties:t,contextName:o}=e;p.log({type:"event",properties:t,contextName:o})}function O({context:e}){function t(r){const c={...e.value,...r},n=e.options.name;j.addEvent(c),A({properties:c,contextName:n})}function o(r){return c=>{t({...e.value,...r,...c})}}return{trackEvent:t,partialTrackEvent:o}}export{E as configure,C as createTrackerContext,v as setLogger,O as withTrackerContext}; | ||
//# sourceMappingURL=index.js.map |
@@ -41,3 +41,3 @@ /** | ||
* | ||
* @param initialProps - Properties witch will initialize the context. | ||
* @param initialProps - Properties which will initialize the context. | ||
* @param options - Options for customizing the Tracker Context. | ||
@@ -74,2 +74,3 @@ * @public | ||
type: 'event'; | ||
contextName?: string; | ||
properties: EventProperties; | ||
@@ -76,0 +77,0 @@ } | { |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.28.4" | ||
"packageVersion": "7.33.6" | ||
} | ||
] | ||
} |
@@ -8,4 +8,4 @@ { | ||
"license": "MIT", | ||
"version": "1.7.0-beta.13", | ||
"description": "A tiny, type-safe and scalable solution for triggering Google Tag Manager track events.", | ||
"version": "1.7.0-beta.14", | ||
"description": "A tiny, type-safe and zero-dependency solution for triggering Google Tag Manager track events.", | ||
"keywords": [ | ||
@@ -45,8 +45,8 @@ "gtm", | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.18.6", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@commitlint/cli": "^17.0.3", | ||
"@commitlint/config-conventional": "^17.0.3", | ||
"@faker-js/faker": "^7.3.0", | ||
"@microsoft/api-extractor": "^7.28.4", | ||
"@commitlint/cli": "^17.3.0", | ||
"@commitlint/config-conventional": "^17.3.0", | ||
"@faker-js/faker": "^7.6.0", | ||
"@microsoft/api-extractor": "^7.33.6", | ||
"@rollup/plugin-commonjs": "^22.0.1", | ||
@@ -58,18 +58,18 @@ "@rollup/plugin-node-resolve": "^13.3.0", | ||
"@semantic-release/git": "^10.0.1", | ||
"@semantic-release/github": "^8.0.4", | ||
"@semantic-release/github": "^8.0.6", | ||
"@semantic-release/npm": "^9.0.1", | ||
"@semantic-release/release-notes-generator": "^10.0.3", | ||
"@types/jest": "^28.1.4", | ||
"@typescript-eslint/eslint-plugin": "^5.30.6", | ||
"@typescript-eslint/parser": "^5.30.6", | ||
"@typescript-eslint/eslint-plugin": "^5.44.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"esbuild": "^0.14.49", | ||
"eslint": "^8.19.0", | ||
"eslint": "^8.28.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-import-resolver-typescript": "^3.2.5", | ||
"eslint-import-resolver-typescript": "^3.5.2", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-n": "^15.2.4", | ||
"eslint-plugin-n": "^15.5.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"husky": "^8.0.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"husky": "^8.0.2", | ||
"jest": "^28.1.2", | ||
@@ -85,6 +85,6 @@ "jest-environment-jsdom": "^28.1.2", | ||
"rollup-plugin-size": "^0.2.2", | ||
"semantic-release": "^19.0.3", | ||
"tsc-alias": "^1.6.11", | ||
"typescript": "^4.7.4" | ||
"semantic-release": "^19.0.5", | ||
"tsc-alias": "^1.7.1", | ||
"typescript": "^4.9.3" | ||
} | ||
} |
@@ -6,5 +6,5 @@ # gtm-event-tracker | ||
A tiny, type-safe and scalable solution for triggering [Google Tag Manager](https://tagmanager.google.com) track events. | ||
A tiny, type-safe and zero-dependency solution for triggering [Google Tag Manager](https://tagmanager.google.com) track events. | ||
It's designed for applications that need to trigger many track events, it solves common problems like writing similar events multiple times, managing "global" required event properties, and debugging track events. It is framework agnostic and configurable, so it probably is the only solution you need for your web application. | ||
It's designed for applications that need to trigger a lot of track events, and it solves common problems like writing similar events multiple times, managing "global" event properties, and debugging track events. This solution is framework agnostic and configurable, so it's probably the only solution you need for your web application for triggering track events. | ||
@@ -21,5 +21,5 @@ | ||
## Why this library over `dataLayer.push`? | ||
- Type-safe events with auto-complete | ||
- Type-safe events | ||
- Less repetition of similar track events | ||
- Centralized way to manage "global" required event properties | ||
- Centralized way to manage "global" event properties | ||
- Easy way to debug your track events | ||
@@ -30,3 +30,3 @@ - Server-side compatible | ||
## Server-Side Rendering (SSR) | ||
This library is SSR compatible, there is only one caveat though. The `targetProperty` isn't available on Server-Side, this means you can't call `trackEvent` function. The reason why is because Google Tag Manager creates the `targetProperty` (`window.dataLayer` by default) only on Client-Side. | ||
This library is SSR compatible, there is only one caveat though. The `targetProperty` isn't available on Server-Side, this means you can't call the `trackEvent` function. The reason why is because Google Tag Manager creates the `targetProperty` (`window.dataLayer` by default) only on Client-Side. | ||
@@ -115,3 +115,3 @@ If you're using some modern framework such as React or Vue, you need to call the `trackEvent` function on `useEffect` or `onMounted` callback. This way you ensure that track events are being only triggered on Client-Side. | ||
##### `trackEvent` | ||
It pushes events to the `targetProperty` (`window.dataLayer` by default). It receives an object as the first argument, and it must contain all required properties in the type provided as the Generic, which in this case, is the `TrackEventProperties`. | ||
It pushes events to the `targetProperty` (`window.dataLayer` by default). It receives an object as the first argument, and it must contain all required properties in the type provided as the Generic (`TrackEventProperties` in this case). | ||
@@ -126,6 +126,6 @@ ```ts | ||
// you can include different properties if you need | ||
// you can add different properties if you need | ||
tracker.trackEvent({ | ||
event: 'notifications_enabled', | ||
channel_id: 'jqk-aof', | ||
channel_id: 'jqk-aof', // this property was not declared in TrackEventProperties type | ||
current_page: 'channel/:id', | ||
@@ -136,3 +136,3 @@ business_context: 'content', | ||
When this function is called an object will be pushed to the `targetProperty`. This object is created combining the tracker context properties and event properties you provide as the first argument. They are combined using the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax), so you can override the "global" event properties from tracker context in your events if you need to. | ||
When this function is called an object will be pushed to the `targetProperty`. This object is created combining the tracker context properties and these event properties you provide. They are combined using the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax), so you can override the "global" event properties from tracker context in your events if you need to. | ||
@@ -139,0 +139,0 @@ **Check out the examples below:** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66405
227