@elgorditosalsero/react-gtm-hook
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -38,3 +38,3 @@ 'use strict'; | ||
return "window." + dataLayerName + " = window." + dataLayerName + " || []; window." + dataLayerName + ".push(" + JSON.stringify(dataLayer) + ")"; | ||
return "window." + dataLayerName + " = window." + dataLayerName + " || [];" + (dataLayer ? "window." + dataLayerName + ".push(" + JSON.stringify(dataLayer) + ")" : ''); | ||
}; | ||
@@ -41,0 +41,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var r=function(e){var t=e.dataLayerName;window[t]?window[t].push(e.data):console.warn("dataLayer "+t+" does not exist, has script be initialized")},i={dataLayer:void 0,dataLayerName:"dataLayer",environment:void 0,nonce:void 0,id:"",injectScript:!0},o=t.createContext(i),d=t.createContext(void 0);function c(e,t){return r({data:t,dataLayerName:null==e?void 0:e.dataLayerName}),e}exports.GTMContext=o,exports.GTMContextDispatch=d,exports.GTMProvider=function(e){var r=e.state,s=e.children,u=t.useReducer(c,a({},i,r)),m=u[0],v=u[1];return t.useEffect((function(){if(r&&0!=r.injectScript){var e=a({},m,r);!function(e){var t,n=(t={dataLayer:e.dataLayer,dataLayerName:e.dataLayerName,environment:e.environment,nonce:e.nonce,id:e.id},{getDataLayerScript:function(){var e,n=document.createElement("script");return t.nonce&&n.setAttribute("nonce",t.nonce),n.innerHTML=(void 0===(e=t.dataLayerName)&&(e="dataLayer"),"window."+e+" = window."+e+" || []; window."+e+".push("+JSON.stringify(t.dataLayer)+")"),n},getNoScript:function(){var e=document.createElement("noscript");return e.innerHTML=function(e,t){var n="";return t&&(n=">m_auth="+t.gtm_auth+">m_preview="+t.gtm_preview+">m_cookies_win=x"),'<iframe src="https://www.googletagmanager.com/ns.html?id='+e+n+'" height="0" width="0" style="display:none;visibility:hidden" id="tag-manager"></iframe>'}(t.id,t.environment),e},getScript:function(){var e=document.createElement("script");return t.nonce&&e.setAttribute("nonce",t.nonce),e.innerHTML=function(e,t,n){var a="";return n&&(a='+">m_auth='+n.gtm_auth+">m_preview="+n.gtm_preview+'>m_cookies_win=x"'),"\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl"+a+";f.parentNode.insertBefore(j,f);\n })(window,document,'script','"+e+"','"+t+"');\n "}(t.dataLayerName,t.id,t.environment),e}}),a=n.getDataLayerScript(),r=n.getScript(),i=n.getNoScript();document.head.insertBefore(a,document.head.childNodes[0]),document.head.insertBefore(r,document.head.childNodes[1]),document.body.insertBefore(i,document.body.childNodes[0])}({dataLayer:e.dataLayer,dataLayerName:e.dataLayerName,environment:e.environment,nonce:e.nonce,id:e.id})}}),[JSON.stringify(r)]),n.createElement(o.Provider,{value:m},n.createElement(d.Provider,{value:v},s))},exports.initialState=i,exports.sendToGTM=r,exports.useGTMDispatch=function(){var e=t.useContext(d);if(void 0===e)throw new Error("dispatchGTMEvent must be used within a GTMProvider");return e}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var r=function(e){var t=e.dataLayerName;window[t]?window[t].push(e.data):console.warn("dataLayer "+t+" does not exist, has script be initialized")},i={dataLayer:void 0,dataLayerName:"dataLayer",environment:void 0,nonce:void 0,id:"",injectScript:!0},o=t.createContext(i),d=t.createContext(void 0);function c(e,t){return r({data:t,dataLayerName:null==e?void 0:e.dataLayerName}),e}exports.GTMContext=o,exports.GTMContextDispatch=d,exports.GTMProvider=function(e){var r=e.state,s=e.children,u=t.useReducer(c,a({},i,r)),m=u[0],v=u[1];return t.useEffect((function(){if(r&&0!=r.injectScript){var e=a({},m,r);!function(e){var t,n=(t={dataLayer:e.dataLayer,dataLayerName:e.dataLayerName,environment:e.environment,nonce:e.nonce,id:e.id},{getDataLayerScript:function(){var e,n,a=document.createElement("script");return t.nonce&&a.setAttribute("nonce",t.nonce),a.innerHTML=(void 0===(n=t.dataLayerName)&&(n="dataLayer"),"window."+n+" = window."+n+" || [];"+((e=t.dataLayer)?"window."+n+".push("+JSON.stringify(e)+")":"")),a},getNoScript:function(){var e=document.createElement("noscript");return e.innerHTML=function(e,t){var n="";return t&&(n=">m_auth="+t.gtm_auth+">m_preview="+t.gtm_preview+">m_cookies_win=x"),'<iframe src="https://www.googletagmanager.com/ns.html?id='+e+n+'" height="0" width="0" style="display:none;visibility:hidden" id="tag-manager"></iframe>'}(t.id,t.environment),e},getScript:function(){var e=document.createElement("script");return t.nonce&&e.setAttribute("nonce",t.nonce),e.innerHTML=function(e,t,n){var a="";return n&&(a='+">m_auth='+n.gtm_auth+">m_preview="+n.gtm_preview+'>m_cookies_win=x"'),"\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl"+a+";f.parentNode.insertBefore(j,f);\n })(window,document,'script','"+e+"','"+t+"');\n "}(t.dataLayerName,t.id,t.environment),e}}),a=n.getDataLayerScript(),r=n.getScript(),i=n.getNoScript();document.head.insertBefore(a,document.head.childNodes[0]),document.head.insertBefore(r,document.head.childNodes[1]),document.body.insertBefore(i,document.body.childNodes[0])}({dataLayer:e.dataLayer,dataLayerName:e.dataLayerName,environment:e.environment,nonce:e.nonce,id:e.id})}}),[JSON.stringify(r)]),n.createElement(o.Provider,{value:m},n.createElement(d.Provider,{value:v},s))},exports.initialState=i,exports.sendToGTM=r,exports.useGTMDispatch=function(){var e=t.useContext(d);if(void 0===e)throw new Error("dispatchGTMEvent must be used within a GTMProvider");return e}; | ||
//# sourceMappingURL=react-gtm-hook.cjs.production.min.js.map |
@@ -31,3 +31,3 @@ import React, { createContext, useReducer, useEffect, useContext } from 'react'; | ||
return "window." + dataLayerName + " = window." + dataLayerName + " || []; window." + dataLayerName + ".push(" + JSON.stringify(dataLayer) + ")"; | ||
return "window." + dataLayerName + " = window." + dataLayerName + " || [];" + (dataLayer ? "window." + dataLayerName + ".push(" + JSON.stringify(dataLayer) + ")" : ''); | ||
}; | ||
@@ -34,0 +34,0 @@ /** |
@@ -14,3 +14,3 @@ { | ||
"description": "Easily manage the Google Tag Manager via Hook", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"license": "MIT", | ||
@@ -35,9 +35,9 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.16.7", | ||
"@testing-library/react": "^12.1.2", | ||
"@babel/core": "^7.17.5", | ||
"@testing-library/react": "^12.1.3", | ||
"@testing-library/react-hooks": "^7.0.2", | ||
"@types/react": "^17.0.38", | ||
"@types/react": "^17.0.39", | ||
"@types/react-dom": "^17.0.11", | ||
"all-contributors-cli": "^6.20.0", | ||
"babel-jest": "^27.4.6", | ||
"babel-jest": "^27.5.1", | ||
"babel-plugin-module-resolver": "^4.1.0", | ||
@@ -52,3 +52,3 @@ "husky": "^7.0.4", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.4" | ||
"typescript": "^4.5.5" | ||
}, | ||
@@ -55,0 +55,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
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
64733