Expand my Community achievements bar.

SOLVED

Need custom script to prevent Page load rule from firing if that same page is being refreshed or reloaded

Avatar

Level 3

So I have a page load rule that fires for our career operations page and populates evar43 and event43.. I also put an event rule on a CTA button on the career operations page, the button is called "job openings" The event rule fires if the button is clicked and populates event44. However the problem is, that when the job opening button is clicked not only is the job listing page opened in new tab, but it also refreshes/reloads the career operations page cause the page load rule to fire again. Obviously this inflates the true count for Career operations page. So I need a custom script to add to the page load rule that basically says do not fire if already on the career operations page.  Any suggestions because I have not idea how I should do this. Oh by the way I am using DTM.

Thank you smiley

Darius Dempsey 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

ParitMittal wrote...

  1. Hi Darius ,
  2.  
  3. Please add the following code in Custom Code section of Adobe Analytics tab of your Page Load rule for "Career Operations Page". This code will suppress the beacon from firing if the career operations Page is refreshed or Reloaded.
 
  1.  
  2. if(window.performance)
  3.  
  4. {
  5.  
  6. if(performance.navigation.type == 1 )
  7. {
  8. alert("Reload");
  9.  
  10. s.abort = true;
  11. }
  12. };

Thanks & Regards

Parit Mittal

 


Hi Darius,

To add to Parit Answer.

Check this first: http://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript

So when the page is loaded for the first time the following:

window.performance.navigation

Return this:

PerformanceNavigation { type: 0, redirectCount: 0 }

Now if you reload the page you should see the following:

PerformanceNavigation { type: 1, redirectCount: 0 }

So Parit code is correct to check if page was reloaded but not to prevent the page load rule to fire. You need to put:

return false;

So the final code should look as follow:

var loadRule = true; if(window.performance) { //Reload of page if(performance.navigation.type  == 1 ){ loadRule = false; } } return loadRule;

I would also advis you to put this custom code in a Data Element to reuse it in all of your rules: example data element : loadRule

//Place in condition of any rule return _satellite.getVar("loadRule");

Best regards.

Alexis Cazes.

Lead Technical Support Engineer

View solution in original post

2 Replies

Avatar

Level 10
Hi Darius , Please add the following code in Custom Code section of Adobe Analytics tab of your Page Load rule for "Career Operations Page".  This code will suppress the beacon from firing if the career operations Page is refreshed or Reloaded. 
if(window.performance) { if(performance.navigation.type  == 1 ) { alert("Reload"); s.abort = true; } };

Thanks & Regards

Parit Mittal

Avatar

Correct answer by
Community Advisor

ParitMittal wrote...

  1. Hi Darius ,
  2.  
  3. Please add the following code in Custom Code section of Adobe Analytics tab of your Page Load rule for "Career Operations Page". This code will suppress the beacon from firing if the career operations Page is refreshed or Reloaded.
 
  1.  
  2. if(window.performance)
  3.  
  4. {
  5.  
  6. if(performance.navigation.type == 1 )
  7. {
  8. alert("Reload");
  9.  
  10. s.abort = true;
  11. }
  12. };

Thanks & Regards

Parit Mittal

 


Hi Darius,

To add to Parit Answer.

Check this first: http://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript

So when the page is loaded for the first time the following:

window.performance.navigation

Return this:

PerformanceNavigation { type: 0, redirectCount: 0 }

Now if you reload the page you should see the following:

PerformanceNavigation { type: 1, redirectCount: 0 }

So Parit code is correct to check if page was reloaded but not to prevent the page load rule to fire. You need to put:

return false;

So the final code should look as follow:

var loadRule = true; if(window.performance) { //Reload of page if(performance.navigation.type  == 1 ){ loadRule = false; } } return loadRule;

I would also advis you to put this custom code in a Data Element to reuse it in all of your rules: example data element : loadRule

//Place in condition of any rule return _satellite.getVar("loadRule");

Best regards.

Alexis Cazes.

Lead Technical Support Engineer