Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Google Analytics or Universal Analytics is installed?

I am trying, through javascript, to identify if Google Analytics or Universal Analytics is loaded.

Some clients still use the old Google Analytics and we want to roll out a javascript that collects data. So i then need to write code for both versions to make sure it gets tracked regardless if its the normal or universal version of analytics.

like image 616
Patrick Avatar asked Dec 15 '22 20:12

Patrick


1 Answers

Classic GA uses the "_gaq" object, and UA uses the "ga" object, so you could check for the existence of either of those

if (_gaq) {
   // using classic GA; do whatever
}

or

if (ga) {
   // using UA; do whatever
}

Hope this helps.

like image 94
nyuen Avatar answered Apr 06 '23 00:04

nyuen