Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Page load rule and data element question

Avatar

Avatar
Validate 25
Level 4
scottt6073095
Level 4

Likes

66 likes

Total Posts

102 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 50
Boost 5
View profile

Avatar
Validate 25
Level 4
scottt6073095
Level 4

Likes

66 likes

Total Posts

102 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 50
Boost 5
View profile
scottt6073095
Level 4

07-02-2017

I created a script that identifies if a visitor's browser is using adblocker. I added the script to the page load rule (top of page) and it works and returns a console.log for the return statement. However, how would I capture the return statement in a data element? I tried creating a data element with custom code to "return adBlockDetection;" but that didn't seem to work?

Am I missing something?

code added to the custom page code in the page load rule (top of page):

var adBlockDetection = (function() {
var test = document.createElement('div');
  test.innerHTML = ' ';
  test.className = 'adsbox';
  document.body.appendChild(test);
   if (test.offsetHeight === 0) {
     console.log("AdBlocker Status: Active");
     return "AdBlocker Status: Active";
    } else {
     console.log("AdBlocker Status: None");
     return "AdBlocker Status: None";
    }
})();

View Entire Topic

Avatar

Avatar
Validate 25
Level 4
scottt6073095
Level 4

Likes

66 likes

Total Posts

102 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 50
Boost 5
View profile

Avatar
Validate 25
Level 4
scottt6073095
Level 4

Likes

66 likes

Total Posts

102 posts

Correct Reply

3 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 50
Boost 5
View profile
scottt6073095
Level 4

08-02-2017

Ok, I got it working and thanks for pointing out the _satellite.getVar("DATA_ELEMENT_NAME"); as it is very handy when testing.

I just needed the return statement outside of the function and it works perfect.

var adBlockDetection = (function() {
var test = document.createElement('div');
  test.innerHTML = ' '; 
  test.className = 'adsbox'; 
  document.body.appendChild(test); 
   if (test.offsetHeight === 0) {
     console.log("AdBlocker Status: Active");
     return "AdBlocker Status: Active";
    } else {
     console.log("AdBlocker Status: None");
     return "AdBlocker Status: None";
    }
})();

return adBlockDetection;

 

Question: If I add it to load at "top of page" then it triggers as page is loaded versus "bottom of page" is waits until page has fully loaded?

thanks again for the help,

Scott