gtm-event-tracker
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -1,10 +0,2 @@ | ||
"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. | ||
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. | ||
Make sure you didn't forget to add Google Tag Manager's script in your application. | ||
If you did but you don't use the default 'window.dataLayer' array, you can set your custom targetProperty with the configure function.`)}function M(){throw new g(`The targetProperty is not an array. | ||
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; | ||
"use strict";function v(t={}){var o;const e=console;let r=(o=t.logger)!=null?o:e;function c(){return r}function n(i){r=i}return{getLogger:c,setLogger:n}}const p=v(),{setLogger:y}=p,{getLogger:E}=p;function w(t){return process.env.NODE_ENV==="production"?`Minified EventTrackerError error #${t}. Visit https://github.com/emkis/gtm-event-tracker#error-codes for the full message.`:t}class a extends Error{constructor(o){const e=w(o);super(e),this.name="EventTrackerError"}}function h(){const t=process.env.NODE_ENV==="production"?"0":"You've called configure function without a configuration object.";throw new a(t)}function x(t){const o=Object.entries(t),e=([c,n])=>n!=null,r=o.filter(e);return Object.fromEntries(r)}function m(){const t=o();function o(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function e(){return t}function r(n){const i=x(n);Object.assign(t,i)}function c(n){n||h(),r(n)}return{get:e,defaults:o,configure:c}}const g=m(),{configure:N}=g;function P(t={}){function o(){var n;return(n=t.configurations)!=null?n:g.get()}function e(){return t.getLogger?t.getLogger():E()}function r({type:n}){const i=()=>o().debugAll,u=()=>o().debugContext,d=()=>o().debugEvents,s=l=>i()||l();return new Map([["event",s(d)],["context-created",s(u)],["context-updated",s(u)]]).get(n)}function c(n){const i=e();r(n)&&i.log(n)}return{log:c}}const f=P();function b(t){const{contextName:o,properties:e}=t;f.log({type:"context-created",contextName:o,properties:e})}function k(t){const{contextName:o,currentProps:e,newProps:r}=t;f.log({type:"context-updated",contextName:o,previousProperties:e,currentProperties:r})}function L(t={},o={}){const e={options:{...o},value:{...t}};function r(){return e.value}function c(n){const i=r(),u={...n};k({contextName:e.options.name,currentProps:i,newProps:u}),e.value=u}return b({contextName:e.options.name,properties:r()}),{context:e,setProps:c}}function T(){const t=process.env.NODE_ENV==="production"?"1":"Triggering events is not possible on server-side. Make sure to only trigger events after your app is running on the client-side.";throw new a(t)}function C(){const t=process.env.NODE_ENV==="production"?"2":"The targetProperty is not defined. Make sure you didn't forget to add Google Tag Manager's script in your application. If you did but you don't use the default 'window.dataLayer' array, you can set your custom targetProperty with the configure function.";throw new a(t)}function O(){const t=process.env.NODE_ENV==="production"?"3":"The targetProperty is not an array. Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.";throw new a(t)}function M(t={}){function o(){var n;return(n=t.configurations)!=null?n:g.get()}function e(){return o().targetProperty()}function r(n){c(),e().push(n)}function c(){const n=()=>typeof window=="undefined",i=()=>!!e(),u=()=>Array.isArray(e());n()?T():i()?u()||O():C()}return{addEvent:r}}const D=M();function V(t){const{properties:o,contextName:e}=t;f.log({type:"event",properties:o,contextName:e})}function j({context:t}){function o(r){const c={...t.value,...r},n=t.options.name;D.addEvent(c),V({properties:c,contextName:n})}function e(r){return c=>{o({...t.value,...r,...c})}}return{trackEvent:o,partialTrackEvent:e}}exports.configure=N,exports.createTrackerContext=L,exports.setLogger=y,exports.withTrackerContext=j; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,1 @@ | ||
export { WarningError } from './warning'; | ||
export { InvalidConfigurationError } from './invalid-configuration'; | ||
export { EventTrackerError } from './error'; |
@@ -1,10 +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 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. | ||
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. | ||
Make sure you didn't forget to add Google Tag Manager's script in your application. | ||
If you did but you don't use the default 'window.dataLayer' array, you can set your custom targetProperty with the configure function.`)}function k(){throw new g(`The targetProperty is not an array. | ||
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}; | ||
function v(t={}){var o;const e=console;let r=(o=t.logger)!=null?o:e;function c(){return r}function n(i){r=i}return{getLogger:c,setLogger:n}}const f=v(),{setLogger:y}=f,{getLogger:E}=f;function w(t){return process.env.NODE_ENV==="production"?`Minified EventTrackerError error #${t}. Visit https://github.com/emkis/gtm-event-tracker#error-codes for the full message.`:t}class a extends Error{constructor(o){const e=w(o);super(e),this.name="EventTrackerError"}}function h(){const t=process.env.NODE_ENV==="production"?"0":"You've called configure function without a configuration object.";throw new a(t)}function x(t){const o=Object.entries(t),e=([c,n])=>n!=null,r=o.filter(e);return Object.fromEntries(r)}function m(){const t=o();function o(){return{debugAll:!1,debugEvents:!1,debugContext:!1,targetProperty:()=>window.dataLayer}}function e(){return t}function r(n){const i=x(n);Object.assign(t,i)}function c(n){n||h(),r(n)}return{get:e,defaults:o,configure:c}}const g=m(),{configure:N}=g;function P(t={}){function o(){var n;return(n=t.configurations)!=null?n:g.get()}function e(){return t.getLogger?t.getLogger():E()}function r({type:n}){const i=()=>o().debugAll,u=()=>o().debugContext,d=()=>o().debugEvents,s=l=>i()||l();return new Map([["event",s(d)],["context-created",s(u)],["context-updated",s(u)]]).get(n)}function c(n){const i=e();r(n)&&i.log(n)}return{log:c}}const p=P();function b(t){const{contextName:o,properties:e}=t;p.log({type:"context-created",contextName:o,properties:e})}function L(t){const{contextName:o,currentProps:e,newProps:r}=t;p.log({type:"context-updated",contextName:o,previousProperties:e,currentProperties:r})}function k(t={},o={}){const e={options:{...o},value:{...t}};function r(){return e.value}function c(n){const i=r(),u={...n};L({contextName:e.options.name,currentProps:i,newProps:u}),e.value=u}return b({contextName:e.options.name,properties:r()}),{context:e,setProps:c}}function T(){const t=process.env.NODE_ENV==="production"?"1":"Triggering events is not possible on server-side. Make sure to only trigger events after your app is running on the client-side.";throw new a(t)}function C(){const t=process.env.NODE_ENV==="production"?"2":"The targetProperty is not defined. Make sure you didn't forget to add Google Tag Manager's script in your application. If you did but you don't use the default 'window.dataLayer' array, you can set your custom targetProperty with the configure function.";throw new a(t)}function O(){const t=process.env.NODE_ENV==="production"?"3":"The targetProperty is not an array. Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly.";throw new a(t)}function M(t={}){function o(){var n;return(n=t.configurations)!=null?n:g.get()}function e(){return o().targetProperty()}function r(n){c(),e().push(n)}function c(){const n=()=>typeof window=="undefined",i=()=>!!e(),u=()=>Array.isArray(e());n()?T():i()?u()||O():C()}return{addEvent:r}}const D=M();function V(t){const{properties:o,contextName:e}=t;p.log({type:"event",properties:o,contextName:e})}function j({context:t}){function o(r){const c={...t.value,...r},n=t.options.name;D.addEvent(c),V({properties:c,contextName:n})}function e(r){return c=>{o({...t.value,...r,...c})}}return{trackEvent:o,partialTrackEvent:e}}export{N as configure,k as createTrackerContext,y as setLogger,j as withTrackerContext}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,1 @@ | ||
export { WarningError } from './warning'; | ||
export { InvalidConfigurationError } from './invalid-configuration'; | ||
export { EventTrackerError } from './error'; |
@@ -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.33.6" | ||
"packageVersion": "7.34.4" | ||
} | ||
] | ||
} |
@@ -8,10 +8,4 @@ { | ||
"license": "MIT", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A tiny, type-safe and zero-dependency solution for triggering Google Tag Manager track events.", | ||
"keywords": [ | ||
"gtm", | ||
"tracking", | ||
"google-tag-manager", | ||
"analytics" | ||
], | ||
"main": "dist/cjs/index.js", | ||
@@ -21,68 +15,5 @@ "module": "dist/es/index.js", | ||
"repository": "git@github.com:emkis/gtm-event-tracker.git", | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"prepare": "husky install", | ||
"clean": "rimraf dist* temp coverage *.tsbuildinfo", | ||
"dev": "npm-run-all clean 'build:ts --watch'", | ||
"build": "npm-run-all clean build:ts build:types", | ||
"build:ts": "rollup --config rollup.config.js", | ||
"build:types": "npm-run-all ts:compile ts:replace-alias", | ||
"lint": "eslint . --ext js,ts", | ||
"test": "npm-run-all test:api-report test:unit:coverage", | ||
"test:unit": "jest", | ||
"test:unit:coverage": "npm-run-all 'test:unit --coverage'", | ||
"test:api-report": "npm-run-all build api-report", | ||
"test:api-report:update": "npm-run-all build 'api-report --local'", | ||
"api-report": "api-extractor run", | ||
"ts:compile": "tsc --project tsconfig.build.json", | ||
"ts:replace-alias": "tsc-alias --project tsconfig.build.json" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@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", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@rollup/plugin-typescript": "^8.3.3", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/commit-analyzer": "^9.0.2", | ||
"@semantic-release/git": "^10.0.1", | ||
"@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.44.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"esbuild": "^0.14.49", | ||
"eslint": "^8.28.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-import-resolver-typescript": "^3.5.2", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-n": "^15.5.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"husky": "^8.0.2", | ||
"jest": "^28.1.2", | ||
"jest-environment-jsdom": "^28.1.2", | ||
"lint-staged": "^13.0.3", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.7.1", | ||
"prettier-eslint": "^15.0.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.76.0", | ||
"rollup-plugin-esbuild": "^4.9.1", | ||
"rollup-plugin-size": "^0.2.2", | ||
"semantic-release": "^19.0.5", | ||
"tsc-alias": "^1.7.1", | ||
"typescript": "^4.9.3" | ||
"node": ">=16" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # gtm-event-tracker | ||
A tiny, type-safe and zero-dependency solution for triggering [Google Tag Manager](https://tagmanager.google.com) track events. | ||
A tiny (1.05KB gzip), type-safe and zero-dependency solution for triggering [Google Tag Manager](https://tagmanager.google.com) track events. | ||
@@ -473,1 +473,13 @@ 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. | ||
| targetProperty | `function` | `() => window.dataLayer` | This is the function that returns the array which the events are going to be pushed into. You should change it if you don't use the default `window.dataLayer`. | | ||
## Error codes | ||
To reduce the amount of data transferred over the network, the full error messages are excluded in the production build of this package. This means in development mode you will be able to see the full error messages when debugging your application, but if you have an error in production, this error will be identified by an error code. | ||
### Available error codes: | ||
| Code | Message | | ||
| ---- | ------- | | ||
| 0 | You've called configure function without a configuration object. | | ||
| 1 | Triggering events is not possible on server-side. Make sure to only trigger events after your app is running on the client-side. | | ||
| 2 | The targetProperty is not defined. Make sure you didn't forget to add Google Tag Manager's script in your application. If you did but you don't use the default 'window.dataLayer' array, you can set your custom targetProperty with the configure function. | | ||
| 3 | The targetProperty is not an array. Either you didn't installed Google Tag Manager correctly or you configured the targetProperty incorrectly. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1807483
0
125
2070
484
0