@elgorditosalsero/react-gtm-hook
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -84,2 +84,7 @@ 'use strict'; | ||
var dataLayerScript = document.createElement('script'); | ||
if (params.nonce) { | ||
dataLayerScript.setAttribute("nonce", params.nonce); | ||
} | ||
dataLayerScript.innerHTML = getDataLayerSnippet(params.dataLayer, params.dataLayerName); | ||
@@ -86,0 +91,0 @@ return dataLayerScript; |
@@ -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 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=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}; | ||
//# sourceMappingURL=react-gtm-hook.cjs.production.min.js.map |
@@ -77,2 +77,7 @@ import React, { createContext, useReducer, useEffect, useContext } from 'react'; | ||
var dataLayerScript = document.createElement('script'); | ||
if (params.nonce) { | ||
dataLayerScript.setAttribute("nonce", params.nonce); | ||
} | ||
dataLayerScript.innerHTML = getDataLayerSnippet(params.dataLayer, params.dataLayerName); | ||
@@ -79,0 +84,0 @@ return dataLayerScript; |
@@ -14,4 +14,4 @@ { | ||
"description": "Easily manage the Google Tag Manager via Hook", | ||
"version": "2.2.0", | ||
"license": "MIT1", | ||
"version": "2.3.0", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
@@ -35,19 +35,19 @@ "module": "dist/react-gtm-hook.esm.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.16.0", | ||
"@babel/core": "^7.16.7", | ||
"@testing-library/react": "^12.1.2", | ||
"@testing-library/react-hooks": "^7.0.2", | ||
"@types/react": "^17.0.35", | ||
"@types/react": "^17.0.38", | ||
"@types/react-dom": "^17.0.11", | ||
"all-contributors-cli": "^6.20.0", | ||
"babel-jest": "^27.3.1", | ||
"babel-jest": "^27.4.6", | ||
"babel-plugin-module-resolver": "^4.1.0", | ||
"husky": "^7.0.4", | ||
"prettier": "^2.4.1", | ||
"prettier": "^2.5.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-router-dom": "^6.0.2", | ||
"react-router-dom": "^6.2.1", | ||
"react-test-renderer": "^17.0.2", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.2" | ||
"typescript": "^4.5.4" | ||
}, | ||
@@ -54,0 +54,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
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
64507
0
532