Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom server side domain name for the Google Tag Manager #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import warn from './utils/warn'
// https://developers.google.com/tag-manager/quickstart

const Snippets = {
tags: function ({ id, events, dataLayer, dataLayerName, preview, auth }) {
tags: function ({ id, src, events, dataLayer, dataLayerName, preview, auth }) {
const gtm_auth = `&gtm_auth=${auth}`
const gtm_preview = `&gtm_preview=${preview}`

const gtm_src = src
if (!id) warn('GTM Id is required')

const iframe = `
<iframe src="https://www.googletagmanager.com/ns.html?id=${id}${gtm_auth}${gtm_preview}&gtm_cookies_win=x"
<iframe src="${gtm_src}/ns.html?id=${id}${gtm_auth}${gtm_preview}&gtm_cookies_win=x"
height="0" width="0" style="display:none;visibility:hidden" id="tag-manager"></iframe>`

const script = `
(function(w,d,s,l,i){w[l]=w[l]||[];
w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js', ${JSON.stringify(events).slice(1, -1)}});
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+'${gtm_auth}${gtm_preview}&gtm_cookies_win=x';
j.async=true;j.src='${gtm_src}/gtm.js?id='+i+dl+'${gtm_auth}${gtm_preview}&gtm_cookies_win=x';
f.parentNode.insertBefore(j,f);
})(window,document,'script','${dataLayerName}','${id}');`

const dataLayerVar = this.dataLayer(dataLayer, dataLayerName)

return {
iframe,
script,
Expand Down
3 changes: 2 additions & 1 deletion src/TagManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const TagManager = {
dataScript
}
},
initialize: function ({ gtmId, events = {}, dataLayer, dataLayerName = 'dataLayer', auth = '', preview = '' }) {
initialize: function ({ gtmId, gtmSrc='https://www.googletagmanager.com', events = {}, dataLayer, dataLayerName = 'dataLayer', auth = '', preview = '' }) {
const gtm = this.gtm({
id: gtmId,
src: gtmSrc,
events: events,
dataLayer: dataLayer || undefined,
dataLayerName: dataLayerName,
Expand Down