Skip to content

Commit

Permalink
Fix: avoid push when datalayer doesnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
alinemorelli committed Aug 29, 2019
1 parent bc79f55 commit 3aaf781
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions dist/TagManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var TagManager = {
_ref2$dataLayerName = _ref2.dataLayerName,
dataLayerName = _ref2$dataLayerName === undefined ? 'dataLayer' : _ref2$dataLayerName;

if (window[dataLayerName]) return window[dataLayerName].push(_dataLayer);
var snippets = _Snippets2.default.dataLayer(_dataLayer, dataLayerName);
var dataScript = this.dataScript(snippets);
document.head.appendChild(dataScript);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-gtm-module",
"version": "2.0.7",
"version": "2.0.8",
"description": "React Google Tag Manager Module",
"main": "dist/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/TagManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const TagManager = {
document.body.insertBefore(gtm.noScript(), document.body.childNodes[0])
},
dataLayer: function ({dataLayer, dataLayerName = 'dataLayer'}) {
window[dataLayerName].push(dataLayer)
if (window[dataLayerName]) return window[dataLayerName].push(dataLayer)
const snippets = Snippets.dataLayer(dataLayer, dataLayerName)
const dataScript = this.dataScript(snippets)
document.head.appendChild(dataScript)
}
}

Expand Down

0 comments on commit 3aaf781

Please sign in to comment.