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
+7.9k Golang : How to use Gorilla webtoolkit context package properly
+5.1k PHP : How to check if an array is empty ?
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+7.7k Golang : Find network service name from given port and protocol
+11.9k Golang : Handle or parse date string with Z suffix(RFC3339) example
+11.4k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+11k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+40.2k Golang : Convert string to array/slice
+50.1k Golang : Check if item is in slice/array
+17.2k Golang : Send email with attachment
+4.4k Golang : Return multiple values from function
+10.5k Golang : Verify Linux user password again before executing a program example