gtm-event-tracker
Advanced tools
Comparing version 1.4.0 to 1.5.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTrackerContext = void 0; | ||
const tracker_context_logs_1 = require("./tracker-context-logs"); | ||
/** | ||
@@ -22,11 +23,32 @@ * Creates a context for track events. | ||
const context = { | ||
options, | ||
options: { ...options }, | ||
value: { ...initialProps }, | ||
}; | ||
function getProps() { | ||
return context.value; | ||
} | ||
function setProps(props) { | ||
context.value = { ...props }; | ||
const updatedProps = { ...props }; | ||
context.value = updatedProps; | ||
} | ||
return { context, setProps }; | ||
function handleSetProps(props) { | ||
const currentProps = getProps(); | ||
const newPropsCopy = { ...props }; | ||
(0, tracker_context_logs_1.logContextUpdated)({ | ||
contextName: context.options.name, | ||
currentProps: currentProps, | ||
newProps: newPropsCopy, | ||
}); | ||
setProps(newPropsCopy); | ||
} | ||
(0, tracker_context_logs_1.logContextCreated)({ | ||
contextName: context.options.name, | ||
properties: getProps(), | ||
}); | ||
return { | ||
context, | ||
setProps: handleSetProps, | ||
}; | ||
} | ||
exports.createTrackerContext = createTrackerContext; | ||
//# sourceMappingURL=tracker-context.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
const data_layer_1 = require("../data-layer"); | ||
const with_tracker_logs_1 = require("./with-tracker-logs"); | ||
/** | ||
@@ -30,4 +31,6 @@ * Accepts a context object returned from `createTrackerContext` function, | ||
function trackEvent(eventProps) { | ||
const eventProperties = { ...context.value, ...eventProps }; | ||
data_layer_1.dataLayer.assertIsAvailable(); | ||
data_layer_1.dataLayer.addEvent({ ...context.value, ...eventProps }); | ||
data_layer_1.dataLayer.addEvent(eventProperties); | ||
(0, with_tracker_logs_1.logEvent)(eventProperties); | ||
} | ||
@@ -34,0 +37,0 @@ function setRepeatedProps(defaultProps) { |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "A type-safe, reusable, and flexible way for triggering Google Tag Manager track events.", | ||
@@ -18,4 +18,3 @@ "keywords": [ | ||
"files": [ | ||
"dist", | ||
"src" | ||
"/dist" | ||
], | ||
@@ -28,3 +27,3 @@ "scripts": { | ||
"build:ts": "tsc --project tsconfig.build.json", | ||
"lint": "eslint src --ext js,ts --fix", | ||
"lint": "eslint . --ext js,ts --fix", | ||
"test": "npm-run-all test:unit test:api-report", | ||
@@ -31,0 +30,0 @@ "test:unit": "jest", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43279
61
943