How to use Google Analytics plugin with Ionic 2? (using earlier ionic-native)


#1

We have an issue where we want to use Google Analytics with our Ionic 2 project. We have unfortunately no time at this point to do an upgrade to the latest Ionic 3 as it would likely require a lot of bugfixing and testing again.

I have tried to install the google analytics plugin like it explains in the docs.

$ ionic plugin add --save cordova-plugin-google-analytics
$ npm install --save @ionic-native/google-analytics

But when I do that I get errors because this seems to want to add ^3.7.0 of it which has a dependency to @ionic-native/core@^3.6.0 - and our Ionic 2 project uses ionic-native ^2.5.1

Is there a way to install an earlier version of this plugin so that I can use it in our project?

I find the upgrade frequency daunting in Ionic, and its really hard to keep track and actually use it for app development without spending a lot of time fiddling with upgrades and dependencies. How do you all handle this in a small development team? We are only 2 developers so there isn’t enough time to keep up and be somewhat confident that we haven’t introduced a ton of new bugs with the latest upgrade - requiring yet another month of user testing.


#2

Why not just upgrade Ionic Native to the required version? This has nothing to do with upgrade to Ionic 3 as you implied in your post. Changes will be minimal, mostly imports.

But if you really don’t want to upgrade: See if Google Analytics was available with your ionic-native version and just use it. The documentation is generated out of comments in the code, so you can just look at the code to see how to use it. If it was not available, well, that’s why software gets updated.


#3

Are you sure? Latter ionic-native examples have moved away from the global static “ionic-native” and have replaced it with specific import for each native components like this:

import { GoogleAnalytics } from ‘@ionic-native/google-analytics’;

And you also have to add these as providers now. Seems to me that it wouldn’t be as easy as just upgrading ionic-native to match whatever the plugin requires.


#4

That’S why I wrote: “Changes will be minimal, mostly imports”. Searching the project for “ionic-native” and fixing it shouldn’t be too hard. Whatever testing is in place should catch all of these anyway.