Google Analytics

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: com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin
W/System.err( 1788): at java.lang.Class.classForName(Native Method)
W/System.err( 1788): at java.lang.Class.forName(Class.java:251)
W/System.err( 1788): at java.lang.Class.forName(Class.java:216)
W/System.err( 1788): at org.apache.cordova.PluginEntry.getClassByName(PluginEntry.java:117)
W/System.err( 1788): at org.apache.cordova.PluginEntry.createPlugin(PluginEntry.java:93)
W/System.err( 1788): at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:281)
W/System.err( 1788): at org.apache.cordova.PluginManager.execHelper(PluginManager.java:232)
W/System.err( 1788): at org.apache.cordova.PluginManager.exec(PluginManager.java:227)
W/System.err( 1788): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
W/System.err( 1788): at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 1788): at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
W/System.err( 1788): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 1788): at android.os.Looper.loop(Looper.java:136)
W/System.err( 1788): at android.os.HandlerThread.run(HandlerThread.java:61)
W/System.err( 1788): Caused by: java.lang.NoClassDefFoundError: com/danielcwilson/plugins/analytics/UniversalAnalyticsPlugin
W/System.err( 1788): … 14 more
W/System.err(
1788): Caused by: java.lang.ClassNotFoundException: Didn’t find class
"com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin" on path:
DexPathList[[zip file
"/data/app/com.ionicframework.myapp526572-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.ionicframework.myapp526572-2,
/vendor/lib, /system/lib]]
W/System.err( 1788): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err( 1788): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
W/System.err( 1788): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
W/System.err( 1788): … 14 more
I/System.out( 1788): Error adding plugin com.danielcwilson.plugins.analytics.UniversalAnalyticsPlugin.
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) {
          analytics.startTrackerWithId("UA-xxxxxxxx-x");
          analytics.trackView($state.current.name);
        } 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.
Requirements:
– user ui-router
– make sure you have ‘$state’ on the params of .run() function

2 Likes

@ylligashi When i added your code : $ionicPlatform.ready(function () {
$rootScope.$on(’$stateChangeSuccess’, function () {
if(typeof analytics !== undefined) {
analytics.startTrackerWithId(“UA-xxxxxxxx-x”);
analytics.trackView($state.current.name);
} 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?