Offline (Google) Analytics

The app I am developing has some functionality that works without the need for an active network connection and I want to be able to track this offline usage. I did find an ios specific plugin on github at https://github.com/nathanhjones/google-analytics-v3-ios-cordova-plugin but can not find a cross platform (ios/android) way to achieve this.

Does anyone have any tips, pointers or other help on how to do this on both android and ios? (other than writing the plugins myself :stuck_out_tongue_closed_eyes:)

you need no plugin follow this behave:
create a service you track your page views in general --> like a wrapper around google analytics tracking. there you check if offline --> store the tracking information in sqlite-table or in a json file (where you want). if you are online --> no need to track offline --> use standard tracking… like ga.pageView or what ever.

If you are using the cordova network-information plugin you can listen on events --> online and offline —> so if you get online again --> check if there are offline tracking information --> send them to your backend or afterwards to google analytics.

1 Like

Thank you, I wasn’t sure if it was acceptable to do this, but I guess as the information is purely for the app owners use that google will not mind this approach. Will write a service.

Thanks again bengtler for all the great work you do here supporting us ionic users.

The Cordova Google Analytics plugin already has the ability to store locally the tracking events and then dispatch them once the device is back online.

1 Like

Thanks for the pointer @woopy. Do you have further information about the offline collection? I see nothing in the documentation or the source about controlling the dispatch and the app in question requires a different scenario to the default Google’s Universal Analytics SDK 3.0.

I don’t really have any documentation regarding the offline collection, but to make sure it’s working, open up Google Analytics Real Time, run your app offline, trigger a couple of events, then go online. You should see in GA that all the events are being send.

That worked for me.

strange… i can not find anything in the source code about offline handling.

@woopy
could you check if the tracking also work if you go offline and restart your app?

I assume it relies on the SDKs default offline behavior, the self queue as you suggested is better for me I think as I can avoid the Google 4am next day cutoff for offline dispatch…

1 Like

I just tested it and yes it does work after going offline, closing the app then restart.

3 Likes

not bad … really… not bad
Thanks for letting us know.