Assigning events for every Hashchange - Single page app | Community
Skip to main content
Level 3
July 20, 2016
Solved

Assigning events for every Hashchange - Single page app

  • July 20, 2016
  • 4 replies
  • 2009 views

Hi,

Is there a way to assign individual events for each hashchange?.If yes, which rule would work.

TIA 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by andrew_r-GrfLbX

not sure if you've changed things for security but your first if statement has "hasvalue" instead of "hashvalue" also it looks like you're putting the code in the custom criteria field which is wrong you need to put it in the Analytics custom page code section (below the evar,props,events section)

 

For criteria you should just have on pushstate or hashchange and generally don't need any other criteria

4 replies

andrew_r-GrfLbX
Level 5
July 21, 2016

I use an JS IF statement within custom code section:

Very basic and cut down version of what I use:

 

if(Stage == "abc") { s.events = "event42"; } else if (Stage == "def") { s.events = "event43"; }

If you're doing it for non pageviews the code is slightly different due to the way s.tl works

m_1985Author
Level 3
July 21, 2016

Thanks for the reply. It doesn't seem to be working for me. I have created the rule and set the condition like the below. any thoughts?

andrew_r-GrfLbX
andrew_r-GrfLbXAccepted solution
Level 5
July 21, 2016

not sure if you've changed things for security but your first if statement has "hasvalue" instead of "hashvalue" also it looks like you're putting the code in the custom criteria field which is wrong you need to put it in the Analytics custom page code section (below the evar,props,events section)

 

For criteria you should just have on pushstate or hashchange and generally don't need any other criteria

m_1985Author
Level 3
July 21, 2016

Thanks for highlighting the typo error. It works perfectly fine when i move all the code to custom page code. thanks again