Resetting data-level variables in single page apps (google tag manager)

Trying to achieve content grouping on a mobile site that is a SPA.

The script looks like this . When I first visit the PDP page, a category variable is set and sent to content groups in the Universal Analytics tag. If after that I go back to the home page, the category variable is not updated and the home page is also grouped in the same content group on the previous PDP page.

This variable is only updated when visiting another PDP page.

I am using a custom PageLoad event to simulate a pageView event. Just want the data layer variables to update during the sequential PageLoad event.

thank

+3


source to share


1 answer


There is an undocumented way to clear the entire DataLayer using this method:

var gtm = window.google_tag_manager['GTM-XXXXXX'];
gtm.dataLayer.reset();

      



Now you don't have to do this, as you can set values ​​you no longer want undefined

in your data file:

dataLayer.push({
  'please_go_away': undefined
});

      

+2


source







All Articles