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):
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.
When you use this command, does the data element return the value you'd expect?