question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Tag Manager Issue

See original GitHub issue

Hi, It’s not clear how can I update Google Tag Manager with barba js? it’s in the <head> tag right now, but I’ve tried initStateChange instead… But it’s dosen’t seems to work… please help.

Barba.Dispatcher.on('initStateChange', function() { (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','GTM-*******'); });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
xcrapcommented, Nov 20, 2017

With the recent Google Tag Manager Script I’ve added this code.

// Barba Google Analytics
Barba.Dispatcher.on('initStateChange', function() { if (window.ga && (document.location.hostname != "localhost" && document.location.hostname != "xcrap.local")) { gtag('config', 'TRACKING-ID-HERE', {'page_path': location.pathname}); } });

The reason I have document.location.hostname != "localhost" && document.location.hostname != "xcrap.local" It’s not to track page changes in my localhost environment. And of course you have to have the normal code above </head> in every page.

2reactions
dnwhtecommented, Nov 9, 2017

Scripts in the document do not get reevaluated on change. In GTM we created a History Change trigger and have the GA tag set to fire on All Pages and the History Change event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot issues - Tag Manager Help - Google Support
Troubleshoot issues · Unpublished changes: Make sure that you have published your container. · Wrong trigger configuration: · Triggers too specific: · Unexpected ......
Read more >
8 Reasons Why a Tag in Google Tag Manager is Not Firing
A Tag in Google Tag Manager is Not Firing? Quick Summary · Trigger misconfiguration · A blocking trigger is being used · You've...
Read more >
5 Common Google Tag Manager Problems | Advance Metrics
5 Common Google Tag Manager Problems and How to Fix Them · 1. Why is my tag firing incorrectly? · 2. Why is...
Read more >
5 Ways to Troubleshoot Your Google Tag Manager Installation
1) Write Good Code and Validate Your JavaScript · 2) Use Google Tag Manager's Preview Link to debug in Firefox with Firebug ·...
Read more >
How to check if Google Tag Manager is Working - Testing GTM
How to check if Google Tag Manager is Working – Testing GTM · Check the source code of the website · Check using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found