Google Analytics javascript in Ionic app


Is it possible to use the javascript version of google analytics in an Ionic app? I am making this Ionic app for a wordpress web site using the wordpress REST Api. I know I don’t have the javascript from the web version when I read posts using the REST api but can I add the google analytics code in my app?

Or do I have to use the native plugin? I am trying to limit the use of plugins as much as possible to avoid third party bugs crippling my app.


Put it in index.html?

Of course you can. In its heart Ionic is just a web app which can run on devices wrapped into some native code.
Check this out:

See: How to use Google analytics with PWA

1 Like

@robinyo: Thanks, that’s what I am looking for.

It can’t be use in an Android app, according my own experience, I did tried the solution. The analytics JavaScript gonna work on iOS or in a PWA but it ain’t gonna work in a WebView on Android

You could try of course and I would be happy to hear I’m wrong

If you want to use analytics on Android, the plugin has then to be use

Pwa the JavaScript lib is fine

@reedrichards thanks, I guess the plugin is a must then… I was looking at the issues the plugin has currently like crashing the app on certain os versions… Oh well.

To be a bit more specific, the problem on Android Webview with Analytics Js is, or at least it was for me, that the events are fired to the Analytics console but the events name or view/page name aren’t correctly send/processed. The console display then a lot of events with different random hashes as name. Furthermore because of that, the events can’t be grouped

But like I said, as far as I saw, iOS and PWA are fine with the JavaScript version of the lib

Regarding your notice, I didn’t noticed any crash on Android because of the plugin personally

Hey, I am trying to do something similar. Any luck with this?