[Enhancement] Google Tag Manager #154
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
How would I go about modifying the current pjax.min.js from having the currently integrated Analytics code to Google Tag Manager instead?
Google is now recommending GTM over Analytics, could we have an example of such integration?
I've never used GTM. Can you post the code you're currently using?
@BehindTheMath
https://developers.google.com/tag-manager/quickstart
I don't mean the initialization code from Google. I mean the code you use to actually log events. Similar to the
ga()function for Google Analytics. What are the function calls? When are they called? What type of data do you pass to them?The Pjax's
analyticsfunction is called after all switches finish, right after thepjax:completeandpjax:successevents are tiggered (see here). If all you want to do is log the page view, you can override that function by doing something like:You can see here how the default function for Google Analytics works.
Alternatively, you can add an event handler for those events and put your code there.
I'm not using pjax in production, and the initialization code from Google is the only code I've used in other projects, with GTM you instead add events in your account within the GTM interface.
So you don't have to add any manual logging code to your site? GTM takes care of that automatically, and you can just look at the dashboard and see all the logged events?
Which events are you looking for that you aren't seeing with Pjax? Just page navigation events?
I did a bit of Googling about how GTM works with SPAs, and from what I've read quickly, it looks like there's a History Change Trigger (see here, for example). Did you try that?
Closing due to lack of follow-up from OP.