Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix bug 1431412] Replace GA script with GTM.
- Loading branch information
1 parent
7550ced
commit 33be297
Showing
7 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- | ||
Read more about our custom configuration and use of Google Analytics here: | ||
TODO: make sure we have a similar public comment about use on SUMO? | ||
https://bugzilla.mozilla.org/show_bug.cgi?id=1122305#c8 | ||
--> | ||
|
||
<!-- Google Tag Manager --> | ||
{% if settings.GTM_CONTAINER_ID %} | ||
{% javascript 'gtm-snippet' %} | ||
{% endif %} | ||
<!-- End Google Tag Manager --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
(function(w) { | ||
'use strict'; | ||
|
||
var GTM_CONTAINER_ID = document.getElementsByTagName('html')[0].getAttribute('data-gtm-container-id'); | ||
|
||
var matches; | ||
var product; | ||
|
||
w.dataLayer = w.dataLayer || []; | ||
|
||
w.gtag = function() { | ||
w.dataLayer.push(arguments) | ||
} | ||
|
||
// If doNotTrack is not enabled, it is ok to add GTM | ||
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=1217896 for more details | ||
if (typeof _dntEnabled === 'function' && !_dntEnabled() && GTM_CONTAINER_ID) { | ||
(function(w,d,s,l,i,j,f,dl,k,q){ | ||
w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});f=d.getElementsByTagName(s)[0]; | ||
k=i.length;q='//www.googletagmanager.com/gtag/js?id=@&l='+(l||'dataLayer'); | ||
while(k--){j=d.createElement(s);j.async=!0;j.src=q.replace('@',i[k]);f.parentNode.insertBefore(j,f);} | ||
}(window,document,'script','dataLayer',[GTM_CONTAINER_ID])); | ||
|
||
w.gtag('js', new Date()); | ||
|
||
// check for first string after '/products/' and before the next '/' | ||
matches = w.location.href.match(/.*?\/products\/([\w-]*)\/?/); | ||
|
||
// product should be first match or null | ||
product = (matches && matches.length > 0) ? matches[1] : null; | ||
|
||
if (product) { | ||
w.gtag('config', GTM_CONTAINER_ID, { | ||
'dimension1': product | ||
}); | ||
} | ||
} | ||
})(window); |