react-gtm-ts
Advanced tools
Comparing version 1.0.20 to 1.0.21
declare const ReactTagManager: { | ||
init: (GTMCode: string) => void; | ||
init: ({ code, debug }: { | ||
code: string; | ||
debug: boolean; | ||
}) => void; | ||
action: ({ event, ...more }: { | ||
@@ -4,0 +7,0 @@ [key: string]: string; |
@@ -28,13 +28,17 @@ "use strict"; | ||
// src/features/init/index.ts | ||
var init = (GTMCode) => { | ||
var init = ({ code, debug = false }) => { | ||
if (typeof window === "undefined") | ||
return; | ||
const elScript = document.createElement("script"); | ||
const script = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});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;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${GTMCode}');`; | ||
const script = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});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;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${code}');`; | ||
elScript.innerHTML = script; | ||
const elNoscript = document.createElement("noscript"); | ||
const noscript = `<iframe src="https://www.googletagmanager.com/ns.html?id=${GTMCode}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`; | ||
const noscript = `<iframe src="https://www.googletagmanager.com/ns.html?id=${code}" height="0" width="0" style="display:none;visibility:hidden"></iframe>`; | ||
elNoscript.innerHTML = noscript; | ||
document.head.insertBefore(elScript, document.head.childNodes[0]); | ||
document.body.insertBefore(elNoscript, document.body.childNodes[0]); | ||
if (debug) { | ||
console.log(`\u{1F7E2} react-gtm-ts - init - ${code}`); | ||
window.react_gtm_ts.debug = true; | ||
} | ||
}; | ||
@@ -44,3 +48,3 @@ | ||
var action = ({ event, ...more }) => { | ||
var _a; | ||
var _a, _b; | ||
if (typeof ((_a = window == null ? void 0 : window.dataLayer) == null ? void 0 : _a.push) !== "undefined") { | ||
@@ -51,2 +55,8 @@ window.dataLayer.push({ | ||
}); | ||
if ((_b = window == null ? void 0 : window.react_gtm_ts) == null ? void 0 : _b.debug) { | ||
console.log("\u{1F7E2} react-gtm-ts - action", { | ||
event, | ||
...more | ||
}); | ||
} | ||
} else { | ||
@@ -53,0 +63,0 @@ console.error( |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"description": "This is a library to facilitate the implementation of Google Tag Manager.", | ||
@@ -8,0 +8,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
7526
128