Adding Google Analytics to a PWA (Ionic 3)


#1

Hi all, I’m looking to add Google Analytics to a quiz competition PWA (Ionic 3), which has no URL structure. I’m considering following the advice in this article, which recommends using Google Tag Manager: http://www.multiminds.eu/2016/12/06/google-analytics-tag-manager-ionic-cordova/

Seems a bit daft to have to include jQuery though but nevertheless thought I would give it a shot. Am I on the right track here or can anyone recommend a better, cleaner solution for adding GA to a URL-less Ionic web app? Any advice is appreciated.


#2

Tag Manager and jQuery definitely sound like overkill.

Just find a way to add a normal Google Analytics JS library to your Ionic app and then call the page events (or however you choose to track your app) manually if the automated tracking doesn’t work (what I expect if your don’t have proper URLs).


#3

Thanks @Sujan12. Is it possible you can recommend a web app compatible JS library that doesn’t require Cordova.


#4

Nope, no experience, sorry.


#5

I use raw Google Analytics at https://DebtsTracker.io/

For each page I override onViewEnter() method and send a pageview message to GA with custom URL.

Works like a charm.


How to use Google analytics with PWA
#7

I have a single code base targeting Android, iOS and Web platforms. Is it possible to use the plugin for all three platforms? Also, do you have any code snippet that you could share? It’d really help me if you could gimme spme code to look at.


#8

We also have the same code base for PWA and our native apps.

Not sure if this is the best approach, but as we are not targetting the cordova Browser platform we implemented vanilla Google Analytics in the PWA and used the GA Cordova plugins for the rest.

We now have to figure out a way to add the GA Javascrript code for the PWA build and not for the Cordova build…