From 3b648c53773d5524099cfa08c4709c348b297fa8 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Mon, 2 Nov 2020 12:28:24 +1100 Subject: [PATCH] Fix rogue referral issue for GTM, GA and AdWords tracking --- README.md | 1 + lib/defaults.js | 1 + lib/plugin.js | 8 ++++++++ lib/plugin.mock.js | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 0f03f8f..bc1c4a1 100755 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ export default { autoInit: true, respectDoNotTrack: true, + pushOriginalLocation: false, scriptId: 'gtm-script', scriptDefer: false, diff --git a/lib/defaults.js b/lib/defaults.js index 21a781a..be62e1f 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -11,6 +11,7 @@ const defaults = { autoInit: true, respectDoNotTrack: true, + pushOriginalLocation: false, scriptId: 'gtm-script', scriptDefer: false, diff --git a/lib/plugin.js b/lib/plugin.js index e51ff25..4f2968d 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -89,5 +89,13 @@ export default function (ctx, inject) { } ctx.$gtm = $gtm inject('gtm', ctx.$gtm) + <% if (options.pushOriginalLocation) { %> + if (process.client) { + window.dataLayer = window.dataLayer || []; + window.dataLayer.push({ + originalLocation: document.location.protocol + '//' + document.location.hostname+document.location.pathname + document.location.search + }); + } + <% } %> <% if (options.pageTracking) { %>if (process.client) { startPageTracking(ctx); }<% } %> } diff --git a/lib/plugin.mock.js b/lib/plugin.mock.js index 89f67f4..07d7d33 100644 --- a/lib/plugin.mock.js +++ b/lib/plugin.mock.js @@ -32,5 +32,13 @@ export default function (ctx, inject) { ctx.$gtm = gtm inject('gtm', gtm) + <% if (options.pushOriginalLocation) { %> + if (process.client) { + window.dataLayer = window.dataLayer || []; + window.dataLayer.push({ + originalLocation: document.location.protocol + '//' + document.location.hostname+document.location.pathname + document.location.search + }); + } + <% } %> <% if (options.pageTracking) { %>if (process.client) { startPageTracking(ctx); }<% } %> }