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";
    }
})();

Accepted Solutions (1)

Accepted Solutions (1)

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

Answers (2)

Answers (2)

Avatar

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

339 likes

Total Posts

2,331 posts

Correct reply

819 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

339 likes

Total Posts

2,331 posts

Correct reply

819 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile
jantzen_belliston-Adobe
Community Manager

09-02-2017

Glad to see you were able to get it working.

Yes, the top of page will load the script well before the bottom of page rule. You can see a lot more detail on load order in DTM in our documentation.

https://marketing.adobe.com/resources/help/en_US/dtm/load_order.html

 

Cheers,
Jantzen

Avatar

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

339 likes

Total Posts

2,331 posts

Correct reply

819 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

339 likes

Total Posts

2,331 posts

Correct reply

819 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile
jantzen_belliston-Adobe
Community Manager

08-02-2017

Hi,

Using a data element would be the correct approach. You can place your code in the custom code section and the code will run once the data element is called. If you wanted this code to run on every page, you could place the data element inside one of your DTM tools in the global variables, or you could use a page load rule. 

With that being said, you mentioned that this method doesn't seem to be working. What issue are you facing? Does the data element return a value when called from the console? You can use the command below in the console to call the data element manually.

_satellite.getVar("DATA_ELEMENT_NAME");

 

When you use this command, does the data element return the value you'd expect?

 

Cheers,
Jantzen