Skip to content

Commit

Permalink
appended pageurl to datalayer (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-S-bisht authored Mar 22, 2023
1 parent fac49ab commit d7e5578
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 74 deletions.
2 changes: 1 addition & 1 deletion dist/helpers/append-gtm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var appendGtm = function appendGtm(_ref) {
if (nonce === '') {
noscript = '\n\t\t(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\': new Date().getTime(),event:\'gtm.js\', ' + eventsVar + ' });var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src= \'https://www.googletagmanager.com/gtm.js?id=\'+i+dl+\'' + authVar + previewVar + '\';f.parentNode.insertBefore(j,f); })(window,document, \'script\', \'' + dataLayerName + '\', \'' + id + '\');\n\t\t';
} else {
noscript = '\n\t\t(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\': new Date().getTime(),event:\'gtm.js\', ' + eventsVar + ' });var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.nonce=' + nonce + ';j.src= \'https://www.googletagmanager.com/gtm.js?id=\'+i+dl+\'' + authVar + previewVar + '\';f.parentNode.insertBefore(j,f); })(window,document, \'script\', \'' + dataLayerName + '\', \'' + id + '\');\n\t\t';
noscript = '\n\t\t(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\': new Date().getTime(),event:\'gtm.js\', ' + eventsVar + ' });var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.nonce=\'' + nonce + '\';j.src= \'https://www.googletagmanager.com/gtm.js?id=\'+i+dl+\'' + authVar + previewVar + '\';f.parentNode.insertBefore(j,f); })(window,document, \'script\', \'' + dataLayerName + '\', \'' + id + '\');\n\t\t';
}
(0, _appendToHtml2.default)({ data: noscript, head: true, reactFlag: reactFlag, nonce: nonce });
/* Google Tag Manager (script) : Goes in the head tag */
Expand Down
8 changes: 8 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ var GTM = {
reactFlag = _ref2.reactFlag,
event = _ref2.event;

// pageurl: window.location.href on gtm, will create discrepency with
// pagename: datalayer.get('pageName')
// because href is calculated at the time and pagename is already present in datalayer
// appending pageurl to datalayer too,
// to sync pagename and pageurl
if (dataLayer && dataLayer.pageName) {
dataLayer.dlPageUrl = dataLayer.dlPageUrl || global.location.href;
}
(0, _dataLayer2.default)({ dataLayerName: dataLayerName, dataLayer: dataLayer, state: state, reactFlag: reactFlag, event: event });
},
fireEvent: _fireEvent2.default
Expand Down
146 changes: 73 additions & 73 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const GTM = {
dataLayerFn({id, dataLayerName, dataLayer, state: 0, reactFlag});
},
appendDL: ({ dataLayerName, dataLayer, state, reactFlag, event }) => {
// pageurl: window.location.href on gtm, will create discrepency with
// pagename: datalayer.get('pageName')
// because href is calculated at the time and pagename is already present in datalayer
// appending pageurl to datalayer too,
// to sync pagename and pageurl
if (dataLayer && dataLayer.pageName) {
dataLayer.dlPageUrl = dataLayer.dlPageUrl || global.location.href;
}
dataLayerFn({dataLayerName, dataLayer, state, reactFlag, event});
},
fireEvent
Expand Down

0 comments on commit d7e5578

Please sign in to comment.