@volenday/google-analytics
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -1,1 +0,1 @@ | ||
exports.defautlGoogleAnalytics = 'UA-99304839-1'; | ||
exports.defautlGoogleAnalytics = 'GTM-KX9NGM4'; |
47
index.js
const { defautlGoogleAnalytics } = require('./config'); | ||
function generateGoogleAnalytics(tags = []) { | ||
if (!tags.length) { | ||
tags = [defautlGoogleAnalytics]; | ||
} | ||
const generateGoogleAnalytics = (tag = defautlGoogleAnalytics) => { | ||
return `<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','${tag}');</script>`; | ||
}; | ||
const firstTag = tags.shift(); | ||
const gtags = tags.map(d => `gtag('config', '${d}');`); | ||
return `<script async src="https://www.googletagmanager.com/gtag/js?id=${firstTag}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${firstTag}'); | ||
${gtags.join('')} | ||
</script>`; | ||
} | ||
module.exports = (tags = '') => { | ||
const ahaAnalytics = defautlGoogleAnalytics; | ||
if (tags !== null && typeof tags !== 'undefined') { | ||
if (typeof tags == 'string') { | ||
if (tags.trim() != '') { | ||
let tagsArr = tags.split(','); | ||
tagsArr.unshift(ahaAnalytics); | ||
return generateGoogleAnalytics(tagsArr); | ||
} else { | ||
return generateGoogleAnalytics([ahaAnalytics]); | ||
} | ||
} else { | ||
let newTags = [...tags]; | ||
newTags.unshift(ahaAnalytics); | ||
return generateGoogleAnalytics(newTags); | ||
} | ||
} else { | ||
return generateGoogleAnalytics([ahaAnalytics]); | ||
} | ||
module.exports = (tag = '') => { | ||
if (!tag) return generateGoogleAnalytics(defautlGoogleAnalytics); | ||
return generateGoogleAnalytics(tag); | ||
}; |
{ | ||
"name": "@volenday/google-analytics", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
2097
13