I am required to integrate Firebase Analytics to the application I am working on.
I found this plugin: https://github.com/arnesson/cordova-plugin-firebase
Which I downloaded. I also downloaded the configuration file from the Firebase project panel and saved it in the root directory as it says in the plugin repository.
But now I do not know how to continue, did someone use it? How do I use it inside the app?
But i still having problems. If I do what the example says:
import { Firebase } from 'ionic-native';
Firebase.getToken()
.then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
.catch(error => console.error('Error getting token', error));
Firebase.onTokenRefresh()
.subscribe((token: string) => console.log(`Got a new token ${token}`));
I get this errors:
"blablabla/ionic-native/dist/es5/index" has no exported member 'Firebase'.
And therefore:
Error: Uncaught (in promise): TypeError: Cannot read property 'getToken' of undefined
What is the benefit of running the native plugin? It isnât required. I looked at it and couldnâ't understand why I needed it, so I didnât install it. Not a snarky question â I genuinely donât understand why itâs better than just following the instructions on the Firebase home page.
How did you include analytics from the firebase instructions? Because, as I see it, analytics functions are only available for Android and IOS native, not for the web. And in ionic 2 we work everything as if it were web.
Thatâs why I tried to use the plugin, because otherwise I can not find a way to do it.
If you did it by following the instructions from firebase, could you tell me how you did it?
Thanks for answering!
Iâm trying to get Firebase Analytics running on mi Ionic 2 app and am running into the same issue that Colo9311 mentions. Can you explain which plugin did you use and how you got it working?
To make this plugin work with ionic 2, my workaround is the following :
Install the plugin : ionic plugin add cordova-plugin-badge
Add this line in /src/declaration.d.ts interface Window { FirebasePlugin: any; }
And follow the instructions on the github page of the plugin. For instance : window.FirebasePlugin.getToken(function(token) { console.log(token); }, function(error) { console.error(error); });
The ionic-native doc is not compliant with this way of importing the plugin.