Google Analytics

Hi koko!, i am getting an error when i try to build to ios, you are using it right now?

Here’s how I’m currently using it, I place at the end of each controller the following :

if (typeof analytics !== 'undefined')

hey i am always getting an (analytics is not defined) ‘Google Analytics plugin could not be loaded’ please help me, how to make it work.
i used the following code.

if (typeof analytics !== ‘undefined’){
console.log(“starting analytics”);
console.log(“Google Analytics plugin could not be loaded.”);

i have included this code in $ionicPlatform.ready function.
please help me out.

Did you try on the device? I’m not sure if it’s supposed to work in the browser.

thanks for the reply…
i already uploaded the app to google store on tuesday but no information was tracked and in my browser console it is getting like ‘Google Analytics plugin could not be loaded’.

I’ve placed the code in the ionicPlatform.ready function embedded in angular’s .run() function
Also note that Real time analytics in GA is not so much real time.
Try running on a device with debug mode and see if you get the console error message

no i didnt get any console error message in debug mode also :frowning:

hey can u please help me in getting google analytics code working for me…
i am always getting analytics undefined.
i even tried included gap:plugin but didnt worked out for me…
pls respond asap
waiting for the reply…

hey i got some error here… can any one know how to solve it.

The error is

W/System.err( 1788): java.lang.ClassNotFoundException:
W/System.err( 1788): at java.lang.Class.classForName(Native Method)
W/System.err( 1788): at java.lang.Class.forName(
W/System.err( 1788): at java.lang.Class.forName(
W/System.err( 1788): at org.apache.cordova.PluginEntry.getClassByName(
W/System.err( 1788): at org.apache.cordova.PluginEntry.createPlugin(
W/System.err( 1788): at org.apache.cordova.PluginManager.getPlugin(
W/System.err( 1788): at org.apache.cordova.PluginManager.execHelper(
W/System.err( 1788): at org.apache.cordova.PluginManager.exec(
W/System.err( 1788): at org.apache.cordova.ExposedJsApi.exec(
W/System.err( 1788): at Method)
W/System.err( 1788): at
W/System.err( 1788): at android.os.Handler.dispatchMessage(
W/System.err( 1788): at android.os.Looper.loop(
W/System.err( 1788): at
W/System.err( 1788): Caused by: java.lang.NoClassDefFoundError: com/danielcwilson/plugins/analytics/UniversalAnalyticsPlugin
W/System.err( 1788): … 14 more
1788): Caused by: java.lang.ClassNotFoundException: Didn’t find class
"" on path:
DexPathList[[zip file
/vendor/lib, /system/lib]]
W/System.err( 1788): at dalvik.system.BaseDexClassLoader.findClass(
W/System.err( 1788): at java.lang.ClassLoader.loadClass(
W/System.err( 1788): at java.lang.ClassLoader.loadClass(
W/System.err( 1788): … 14 more
I/System.out( 1788): Error adding plugin
D/PluginManager( 1788): exec() call to unknown plugin: UniversalAnalytics
D/CordovaLog( 1788): file:///android_asset/www/js/app.js: Line 23 : in platform.ready method
I/chromium( 1788): [INFO:CONSOLE(23)] “in platform.ready method”, source: file:///android_asset/www/js/app.js (23)indent preformatted text by 4 spaces

Have you tried to cordova rm then cordova add the plugin back ?

Thanks @koko
In my current project it is still showing as "undefined"
but when i tried creating a new sample project and included the plugin in that new project, i got the above error, after removing and re-add plugin for several times, the error was gone and it is working fine.

The thing here is both my current project and sample project has the same code, it is working in sample project and undefined in current project.

can u let me know why the type is always getting undefined in my current project and how can i resolve it.

I don’t understand what I’m supposed to replace ‘name-of-template’ with.

Is it the .state, the url or the templateUrl? I’ve tried all of those and I don’t get anything registering.

I’ve previously used the analytics plugin with PhoneGap Build and it works fine. But the syntax is very different.

Anyone give me how to use ? and what is purpose for google analytics

I had a problem, your post helped me, thanks.

try adding on the .run function of application

$ionicPlatform.ready(function () {
      $rootScope.$on('$stateChangeSuccess', function () {
        if(typeof analytics !== undefined) {
        } else {
          console.log("Google Analytics Unavailable");

This will give you each state whenever it changes so you do not need to add it to each controller.
– user ui-router
– make sure you have ‘$state’ on the params of .run() function


@ylligashi When i added your code : $ionicPlatform.ready(function () {
$rootScope.$on(’$stateChangeSuccess’, function () {
if(typeof analytics !== undefined) {
} else {
console.log(“Google Analytics Unavailable”);
}); This tracks real time users but i cant get audience info, Device information, Network information and all under audience tab in ga dashboard. Can u help me please

Hi guys, I had the same issue with “analytics is not defined” and I solved it this way:

cordova plugin remove cordova-plugin-whitelist
ionic platform remove android // whatever your platform

And then I add them again.

cordova plugin add cordova-plugin-whitelist
ionic platform add android

Do not forget that GA will only work by running it on your mobile device.
I hope this post has helped.

Now google analytics stop working from october 2019, what about existing app where i am using google analytics for tracking, if google analytics stops working what about the installed google analytics plugin it will throw an error or it will work or I need to remove the code from my project please help me out

Can we use property ID instead of tracking code? Does it works fine? Small Confusion. Please help!

Maybe helps?