revolunet / angular-google-analytics

Google Analytics tracking for your AngularJS apps
MIT License
652 stars 179 forks source link

I'm using ONSEN.io Would be a problem? #189

Closed joaomarcusjesus closed 7 years ago

joaomarcusjesus commented 7 years ago

Hi Guys,

I'm new with angular and google anlytics.

In my application I'm using onsen, which works with pushPage (to stack) and popPage (to unstack) methods and my intention is to get the user views and send to the platform google analytics.

I'm facing the following problem...

 var app = ons.bootstrap(['onsen', 'angular-google-analytics'])

 .config(['AnalyticsProvider', function (AnalyticsProvider) {
    AnalyticsProvider.setHybridMobileSupport(true);
    AnalyticsProvider.trackUrlParams(true);
    AnalyticsProvider.trackPages(true);
    AnalyticsProvider.setAccount([
        { tracker: 'XXXXXX', name: "XXXXX" },
    ]);
  }])

 .run(['Analytics', function(Analytics) { 

 }])

 .controller('OneController', function ($scope, Analytics, $document) {

     var _this = this;

     $document.on('postpush', function(event) {
        console.log(event.navigator.topPage.name);
        _this.analycticSend(event.navigator.topPage.name);
     });

     _this.analycticSend = function(tracker) {
        Analytics.trackPage(tracker);
     };
 });`

In index.html

 <ons-template id="one.html" ng-controller="OneController">
    <ons-page>
      <ons-toolbar>
        <div class="left">
          <ons-back-button>Back</ons-back-button>
        </div>
        <div class="center">Navigation</div>
      </ons-toolbar>

      <section style="padding: 10px">
          <div class="container">
              <span>{{ $id }}</span>
              <ons-button type="button" id="btnId" alt="btn" ng-click="nav.pushPage('two.html')">Page</ons-button>
          </div>
      </section>
    </ons-page>
  </ons-template>`

Thanks guys!!