javascript - Firing GTM event and simultaneously updating history API with replaceState -


when firing gtm tag this:

datalayer.push({         'event': 'gtm.trackevent',         'eventcategory': 'offices',         'eventaction': 'search',         'eventlabel': '1234ab',         'eventnoninteraction': 1 }); 

while updating url bar history api so:

window.history.replacestate({}, '', '/offices?office=1234ab'); 

the url bar behaves unexpectedly. happens this:

  1. the url bar starts current state (e.g. /path?office=current-param
  2. the url bar gets replaced history api (e.g. /path?office=1234ab)
  3. the url bar gets replaced first state of page view (e.g. /path?param=first-state

the way when third part doesn't occur, when disable/comment gtm tag. therefore i'm assuming gtm doesn't handle states history api well.

i wondering if there possibility disable whatever happens history api inside gtm.

update eventcallback property, can ensure whenever event has been fired, history replacestate gets called afterwards, results in correct end state (/path?office=1234ab). code have is:

datalayer.push({         'event': 'gtm.trackevent',         'eventcategory': 'offices',         'eventaction': 'search',         'eventlabel': '1234ab',         'eventnoninteraction': 1,         'eventcallback': function() {             window.history.replacestate({}, '', '/offices?office=1234ab');         } }); 

still see jump original state new state: (point 2 , 3 switched)

  1. the url bar starts current state (e.g. /path?office=current-param
  2. the url bar gets replaced first state of page view (e.g. /path?param=first-state
  3. the url bar gets replaced history api (e.g. /path?office=1234ab)


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -