Nativescript Google Analytics
Release Notes
Add Plugin
tns plugin add nativescript-google-analytics-demographics
Get Config files
- iOS instructions
- Android instructions
- Click the "Get a Configuration File" instrutctions
- Add the platform specific config file you just downloaded to its respective App_Resources/{platform} folder
Initalize the tracker in app.js
PLAIN JS
var application = ;var googleAnalytics = ;applicationmainModule = "main-page";applicationcssFile = "./app.css";if applicationios//iOSvar __extends = this__extends || {for var p in b if b dp = bp;{ thisconstructor = d; }__prototype = bprototype;dprototype = ;};var appDelegate = {;{_super;}appDelegateprototype {; //Module Code to initalize};appDelegateObjCProtocols = UIApplicationDelegate;return appDelegate;}UIResponder;applicationiosdelegate = appDelegate;else//ANDROIDapplication;applicationstart;{googleAnalytics;}
Typescript
var application = ;;applicationmainModule = "main-page";applicationcssFile = "./app.css"; if applicationios //iOS implements UIApplicationDelegate public static ObjCProtocols = UIApplicationDelegate; : boolean ; //Module Code to initalize return true; applicationiosdelegate = MyDelegate; else //ANDROID application; applicationstart; { googleAnalytics;}
Methods
Initalize Options
// category and action are not optional, label and value aregoogleAnalytics;
Log Event
// category and action are not optional, label and value aregoogleAnalytics;
Log ScreenView
// category and action are not optional, label and value aregoogleAnalytics;
Flush Message queue (dispatch)
googleAnalytics;
Log exceptions
googleAnalytics;//orgoogleAnalytics;
Log timings
//OPTION 1: Auto (Time is stored internally, just call stopTimer when you're done)googleAnalytics;/* ... time passes as you do something ... */googleAnalytics;//OPTION 2: Raw, calculate and send yourselfgoogleAnalytics;
Issues
Android
Error: Could not find com.google.android.gms:play-services-analytics:8.4.0
Resolution: *Open the Android Studio SDK manager, make sure all of your build tools are up to date. Then make sure your Google Play Services and Google Repository packages are up to date. In the Android Studio sdk manager, you'll find these under the "SDK Tools" tab. If you are using the standalone sdk manager, you would scroll down to the "Extras" section at the bottom and update them there *