sitefinitysteve / nativescript-google-analytics

Apache License 2.0
23 stars 14 forks source link

Installing with TypeScript #16

Closed unostella closed 7 years ago

unostella commented 7 years ago

Anyone tried to install that plugin on {N}'s TypeScript version? Currently docs provide only regular JS code

bradmartin commented 7 years ago

Yep, here's some sample from my app.ts

import { initalize as googleAnalyticsInitialize, dispatch as googleAnalyticsDispatch } from 'nativescript-google-analytics';
import { isAndroid, isIOS } from 'platform';

/// Android specifics
if (isAndroid) {

    /// Android onLaunch    
    application.onLaunch = ((intent) => {

        /// initialize Google Analytics
        googleAnalyticsInitialize({
            trackingId: 'UA-MyKey-2',
            dispatchInterval: 45
        })

    })
}

/// iOS specifics
if (isIOS) {

     /// Google Analytics
     class MyDelegate extends UIResponder implements UIApplicationDelegate {
         public static ObjCProtocols = [UIApplicationDelegate];

         applicationDidFinishLaunchingWithOptions(applicationlication: UIApplication, launchOptions: NSDictionary): boolean {
             googleAnalyticsInitialize({
                 trackingId: 'UA-MyKey-2',
                 dispatchInterval: 45
             });
             return true;
         }

     }

     application.ios.delegate = MyDelegate;
}
sitefinitysteve commented 7 years ago

Thx @brad

TS Code is also in the readme now