Detect if Google Analytics and Developer Media are loaded properly or not
This is for my own future reference. I need a way to check if Digital Media and Google Analytics JavaScript objects are loaded properly. There are browser's extensions such as Ghostery and Disconnect that will interfere or surrogate JavaScript objects and nullify the analytics behind the ads.
Here you go!
<script type="text/javascript">
window.addEventListener('load', function()
{
if(typeof DMAds==='undefined')
{
console.log('Developer Media is not loaded');
}
else
{
console.log('Developer Media is loaded');
}
if(window._gaq && (typeof window._gaq.I!== 'undefined'))
{
console.log('Classic Google Analytics is loaded');
}
else
{
console.log('Classic Google Analytics is not loaded');
}
console.log(window._gaq.I.prefix);
}, false);
</script>
If the browser viewing the page with above JavaScript codes equips with Ghostery or Disconnect. You will see Developer Media is not loaded
and Classic Google Analytics is not loaded
under your browser's Console
tab.
References:
https://marthijnhoiting.com/detect-if-someone-is-blocking-google-analytics-or-google-tag-manager/
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.3k AWS S3 : Prevent Hotlinking policy
+29.6k Golang : All update packages with go get command
+12.4k Golang : Loop each day of the current month example
+13k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+67.4k Golang : How to convert character to ASCII and back
+10.1k Golang : "https://" not allowed in import path
+14.7k Golang : Convert IPv4 address to decimal number(base 10) or integer
+12.6k Golang : Delete files by extension
+5.1k Mac OSX : Find large files by size
+3.9k Fix yum-complete-transaction error
+6.2k Golang : Emulate NumPy way of creating matrix example
+4.8k Linux : How to fix Brother HL-1110 printing blank page problem