-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
30 lines (26 loc) · 1.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* jshint node: true */
'use strict';
module.exports = {
name: 'ember-cli-google-tag-manager',
contentFor: function(type, config){
config = config.googleTagManager
const appId = config && config.appId
const gtmAuth = config && config.gtmAuth
const gtmPreview = config && config.gtmPreview
const shouldRenderEnv = (gtmAuth && gtmPreview);
if (!appId) {
return ''
}
if (type === 'head'){
if (shouldRenderEnv) {
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+" + "'>m_auth="}${ gtmAuth }>m_preview=${ gtmPreview }>m_cookies_win=x'` + `;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','${ appId }');</script>`;
}
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','${ appId }');</script>`;
} else if (type === 'body'){
if (shouldRenderEnv) {
return `<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=${ appId }>m_auth=${ gtmAuth }>m_preview=${ gtmPreview }>m_cookies_win=x` + ' height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
}
return `<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=${ appId } height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>`;
}
},
};