sitefinitysteve / nativescript-google-analytics

Apache License 2.0
23 stars 14 forks source link

Using this module with Native Script Angular? #21

Closed kerberosargos closed 7 years ago

kerberosargos commented 7 years ago

Hello, I am newbie with Native Script I am developing a project with NS Angular 2. I need some help implements your module to my project. How can I do that?

dvh91 commented 7 years ago

app.component.ts:

import * as googleAnalytics from 'nativescript-google-analytics';

  ngOnInit() {
    this.initAnalytics();
  }
  initAnalytics(){
    googleAnalytics.initalize({
      trackingId: 'UA-*********-1',
      dispatchInterval: 5,
      logging: true
    });
  }

then you can see docs for the logging function. dont forget to import the library.

kerberosargos commented 7 years ago

Thank you very much. So must I put above codes to somewhere?

if (application.ios) {
    //IOS
    var __extends = this.__extends || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        __.prototype = b.prototype;
        d.prototype = new __();
    };

    var appDelegate = (function (_super) {
        __extends(appDelegate, _super);
        function appDelegate() {
            _super.apply(this, arguments);
        }

        appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
            initAnalytics(); //Module Code to initalize
        };

        appDelegate.ObjCProtocols = [UIApplicationDelegate];
        return appDelegate;
    })(UIResponder);
    application.ios.delegate = appDelegate;
}else{
    //ANDROID
    application.on(application.launchEvent, function (args) {
        initAnalytics(); //Module Code to initalize
    });

}
dvh91 commented 7 years ago

nope. thats a js code for those who dont use typescript and since you mentioned you're using angular along with NS, I assume you're using typescript.

kerberosargos commented 7 years ago

One more question I have multiple pages in my project. Therefore I try to create reusable codes. For example I would like to create one code page for your module and import it to other pages? Can I do that as below? is that correct approach?

analytics.services.ts

import { Component } from "@angular/core";
import { Injectable } from "@angular/core";
import * as googleAnalytics from 'nativescript-google-analytics';

@Injectable()
export class AnalyticsService {

    public constructor() { }

    public initAnalytics(){
    googleAnalytics.initalize({
      trackingId: 'UA-*********-1',
      dispatchInterval: 5,
      logging: true
    });
  }
}

countries.module.ts

import { Component } from "@angular/core";
import {AnalyticsService} from '../services/analytics.service.ts';

@Component({
    selector: "countries",
    templateUrl: "pages/countries.component.html",
    providers: [AnalyticsService]
})
export class CountriesComponent {

      constructor(private  _AnalyticsService: AnalyticsService) {
}

    ngOnInit() {
         _AnalyticsService.initAnalytics();
     }
}
sitefinitysteve commented 7 years ago

Thx @dvh91 I haven't dabbled in ng2 yet, I'll add this to the docs!

@kerbooo you just want to initialize the tracker the once

kerberosargos commented 7 years ago

@sitefinitysteve Yes I wan to initialize just one.

sitefinitysteve commented 7 years ago

Okay just do it as defined above then... Once that's done is now running on native code in iOS or Android so the other methods in the plugin should just work fine because they grab the current tracker instance.

kerberosargos commented 7 years ago

@dvh91 I am getting error like "module not finding" when I using above code;

import * as googleAnalytics from 'nativescript-google-analytics';

  ngOnInit() {
    this.initAnalytics();
  }

  initAnalytics(){
    googleAnalytics.initalize({
      trackingId: 'UA-*********-1',
      dispatchInterval: 5,
      logging: true
    });
  }
kerberosargos commented 7 years ago

I did not understand what I will do. Could you give me full code sample?

27 Ara 2016 19:15 tarihinde "Steve McNiven-Scott" notifications@github.com yazdı:

Okay just do it as defined above then... Once that's done is now running on native code in iOS or Android so the other methods in the plugin should just work fine because they grab the current tracker instance.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269346538, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1n0M3v7nZG9IcKTRFYDZA9QWhyZi4Vks5rMTmFgaJpZM4LWQdV .

sitefinitysteve commented 7 years ago

I haven't even dabbled in ns2 so not really, sorry :/

On Dec 27, 2016 1:05 PM, "Kerberos" notifications@github.com wrote:

I did not understand what I will do. Could you give me full code sample?

27 Ara 2016 19:15 tarihinde "Steve McNiven-Scott" < notifications@github.com> yazdı:

Okay just do it as defined above then... Once that's done is now running on native code in iOS or Android so the other methods in the plugin should just work fine because they grab the current tracker instance.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269346538, or mute the thread https://github.com/notifications/unsubscribe-auth/ AK1n0M3v7nZG9IcKTRFYDZA9QWhyZi4Vks5rMTmFgaJpZM4LWQdV .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269360725, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6PddWV9W6GXuek4dLNiwFxC-OFIYks5rMVLzgaJpZM4LWQdV .

kerberosargos commented 7 years ago

OK thank you. So I can't use this module with NG2 I understood.

27 Ara 2016 21:12 tarihinde "Steve McNiven-Scott" notifications@github.com yazdı:

I haven't even dabbled in ns2 so not really, sorry :/

On Dec 27, 2016 1:05 PM, "Kerberos" notifications@github.com wrote:

I did not understand what I will do. Could you give me full code sample?

27 Ara 2016 19:15 tarihinde "Steve McNiven-Scott" < notifications@github.com> yazdı:

Okay just do it as defined above then... Once that's done is now running on native code in iOS or Android so the other methods in the plugin should just work fine because they grab the current tracker instance.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269346538, or mute the thread https://github.com/notifications/unsubscribe-auth/ AK1n0M3v7nZG9IcKTRFYDZA9QWhyZi4Vks5rMTmFgaJpZM4LWQdV .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269360725, or mute the thread https://github.com/notifications/unsubscribe-auth/ ABeI6PddWV9W6GXuek4dLNiwFxC-OFIYks5rMVLzgaJpZM4LWQdV .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269361602, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1n0FU7W83roNTplW1fdoNLodsb1SLQks5rMVSngaJpZM4LWQdV .

dvirhazout commented 7 years ago

You surely can use it with ng2. See my first comment. Implement it in app.component and test if it works.

kerberosargos commented 7 years ago

I have tried as you wrote. But I am giving error. Did you try that before?

27 Ara 2016 21:18 tarihinde "Dvir Hazout" notifications@github.com yazdı:

You surely can use it with ng2. See my first comment. Implement it in app.component and test if it works.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269362570, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1n0PSGet_lDRoEOdyKa5NeSS0Ry2tnks5rMVZ1gaJpZM4LWQdV .

dvirhazout commented 7 years ago

Yes. I did. Post your whole component code

kerberosargos commented 7 years ago

@dvirhazout I am sorry for late. My project's whole code as below;

app.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptHttpModule } from "nativescript-angular/http";

import { AppComponent } from "./app.component";
import { CountriesComponent } from "./pages/countries.component";

@NgModule({
    declarations: [AppComponent, CountriesComponent],
    bootstrap: [AppComponent],
    imports: [NativeScriptModule, NativeScriptHttpModule],
    schemas: [NO_ERRORS_SCHEMA]
})
export class AppModule { }

main.ts

import { platformNativeScriptDynamic } from "nativescript-angular/platform";

import { AppModule } from "./app.module";

platformNativeScriptDynamic().bootstrapModule(AppModule);

app.component.ts

import { Component } from "@angular/core";

@Component({
  selector: "my-app",
  template: "<countries></countries>"
})
export class AppComponent {}

countries.component.ts

import { Component } from "@angular/core";
import { JsonService } from '../services/json.service';
import { AdmobService } from '../services/admob.service';
import { AnalyticsService } from '../services/analytics.service';

@Component({
    selector: "countries",
    templateUrl: "pages/countries.component.html",
    providers: [AdmobService, AnalyticsService]
})
export class CountriesComponent {

    constructor(private _AdmobService: AdmobService, private _AnalyticsService: AnalyticsService) {
               _AdmobService.createBanner();        
    }

    ngOnInit() {
        this. _AnalyticsService.initAnalytics(); 
     }
}

analytics.service.ts


import { Component } from "@angular/core";
import { Injectable } from "@angular/core";
import * as googleAnalytics from 'nativescript-google-analytics';

@Injectable()
export class AnalyticsService {

  public constructor() { }

  public initAnalytics() {
    googleAnalytics.initalize({
      trackingId: 'UA-XXXXXXX-9',
      dispatchInterval: 5,
      logging: true
    });
  }
}
sitefinitysteve commented 7 years ago

I'm just going to close because this isn't a plugin issue

kerberosargos commented 7 years ago

@sitefinitysteve Yes this not issue we know. But this post helps to so many people. I think you don't close that.

sitefinitysteve commented 7 years ago

Indeed the post isn't going anywhere, it'll still be visible, but doesn't need to be an open issue on this plugin as it's unrelated.

On Dec 28, 2016 9:24 AM, "Kerberos" notifications@github.com wrote:

@ sitefinitysteve Yes this not issue we know. But this post helps to so many people. I think you don't close that.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269483626, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6NPqTWTZ-S_RV49jHi0HnPZIKxjaks5rMnE4gaJpZM4LWQdV .

kerberosargos commented 7 years ago

@sitefinitysteve OK thank you. When will you add Angular 2 property to your plugin?

sitefinitysteve commented 7 years ago

I don't plan on it... Not an angular guy do I'm not sure what you mean. If someone submits a PR to do whatever it is I will accept it though.

On Dec 28, 2016 9:34 AM, "Kerberos" notifications@github.com wrote:

@sitefinitysteve https://github.com/sitefinitysteve OK thank you. When will you add Angular 2 property to your plugin?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269484757, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6F8qAiikG08KkYYd_zJBu5wyWNKFks5rMnNdgaJpZM4LWQdV .

kerberosargos commented 7 years ago

I can't understand what you mean too. I think you are angry. Thank you very much for your plugin. But I would like to use it with NativeScript with Angular 2. I wrote I am newbie at the begining. I am not expert Angular even NativeScript I try to learn. I mean I am stranger for both platform and I need help. I wrote here because may be somebody help me.

2016-12-28 17:39 GMT+03:00 Steve McNiven-Scott notifications@github.com:

I don't plan on it... Not an angular guy do I'm not sure what you mean. If someone submits a PR to do whatever it is I will accept it though.

On Dec 28, 2016 9:34 AM, "Kerberos" notifications@github.com wrote:

@sitefinitysteve https://github.com/sitefinitysteve OK thank you. When will you add Angular 2 property to your plugin?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269484757, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6F8qAiikG08KkYYd_ zJBu5wyWNKFks5rMnNdgaJpZM4LWQdV

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269485448, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1n0KZc0_zMIHYfXWib1ZjCqGZziYoCks5rMnSSgaJpZM4LWQdV .

sitefinitysteve commented 7 years ago

Not angry! ;) But this works fine with angular as the dude above can attest... I just can't help you with it because I do not work with angular, and since this is not a plugin issue but rather a fundamental angular or NS functional issue it shouldn't live here in this plugin. Perhaps ask the slack channel or stack overflow?

On Dec 28, 2016 9:51 AM, "Kerberos" notifications@github.com wrote:

I can't understand what you mean too. I think you are angry. Thank you very much for your plugin. But I would like to use it with NativeScript with Angular 2. I wrote I am newbie at the begining. I am not expert Angular even NativeScript I try to learn. I mean I am stranger for both platform and I need help. I wrote here because may be somebody help me.

2016-12-28 17:39 GMT+03:00 Steve McNiven-Scott notifications@github.com:

I don't plan on it... Not an angular guy do I'm not sure what you mean. If someone submits a PR to do whatever it is I will accept it though.

On Dec 28, 2016 9:34 AM, "Kerberos" notifications@github.com wrote:

@sitefinitysteve https://github.com/sitefinitysteve OK thank you. When will you add Angular 2 property to your plugin?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269484757, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6F8qAiikG08KkYYd_ zJBu5wyWNKFks5rMnNdgaJpZM4LWQdV

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript- google-analytics/issues/21#issuecomment-269485448, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1n0KZc0_ zMIHYfXWib1ZjCqGZziYoCks5rMnSSgaJpZM4LWQdV .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sitefinitysteve/nativescript-google-analytics/issues/21#issuecomment-269487132, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeI6GtRwB5TY6I9oLL7gADuBVyNr9W2ks5rMneBgaJpZM4LWQdV .

kerberosargos commented 7 years ago

OK thank you very much. Actually I am waiting @dvirhazout 's answer. Now I am asking to other people over from stackoverflow.