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

Repeated Google tag ID #11

Open
vincentmajor opened this issue Aug 27, 2020 · 3 comments
Open

Repeated Google tag ID #11

vincentmajor opened this issue Aug 27, 2020 · 3 comments

Comments

@vincentmajor
Copy link

The Google tag ID appears to be repeated twice and is not being recognized by Google Analytics.

Excerpt from the demo site but the same happens with my local version:

<script async="" src="https://www.googletagmanager.com/gtm.js?id=GTM-000000GTM-000000"></script>
...
<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=GTM-000000' + i + dl;
        f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'GTM-000000');
</script>

Note the repeated tag (GTM-000000) in the first line which appears to be caused by concatenating the tag to the url already containing the tag.

@akarshjg
Copy link

akarshjg commented Sep 14, 2020

True, I fixed this issue locally by deleting GTM-000000 in j.src as shown below -

<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', '{{ .Site.Params.googleTagManagerID }}');
</script>

@ascalco
Copy link

ascalco commented Jul 16, 2021

Found the same issue. For future references, go inside "head.html", keep {{ .Site.Params.googleTagManagerID }} and remove +i +dl.

@kamui
Copy link

kamui commented Sep 6, 2021

Ran into this as well. Thanks @ascalco!

Edit:

Actually, if you want to do this the way the GTM snippet is represented you want to change the line to:

            'https://www.googletagmanager.com/gtm.js?id=' + i + dl;

Then, the script will inject the GTM code via the dataLayer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants