angulartics / angulartics

Analytics for AngularJS applications.
http://angulartics.github.io/
MIT License
1.94k stars 415 forks source link

Double page views with multiple angular.module #228

Closed daniel-obadia closed 9 years ago

daniel-obadia commented 10 years ago

Hi!

We just recently found the https://github.com/luisfarzati/angulartics/issues/97 bug as we had really low bounce rates on our app. Once we upgraded to the latest version (v0.17.0) that had the fix for this we thought all was going to be fixed.

As it turned out, it didn't get fixed and here's why we are getting double page views :

Our AngularJS app is using several "angular.module" with one of them being the main application.

Heres the structure : Main : var app = angular.module("myApp", ['ngCookies', 'bardo.directives', 'leaflet-directive', 'ngSanitize', 'vr.directives.slider', 'ui.router', 'ui.bootstrap.modal', 'ui.bootstrap.popover', 'ngRoute', 'angulartics', 'angulartics.google.analytics', 'angular-flexslider']);

Secondary : var mySearch = angular.module("mySearch", ['myApp', 'ui.router', 'confirmButton', 'ngRoute']) Here we define several states and URLS...

As you can see the mySearch app depends on "myApp" app. It looks as if the use of two angular.modules makes Angulartics send double page views.

As soon as we add "$analyticsProvider.virtualPageviews(false);" to the seconday "mySearch" module it stops sending the double page views.

Has anyone encountered this and what would be a long term fix for this?

Thanks

timelf123 commented 10 years ago

Hello and thanks for the feedback! So we can narrow some things down, are you sure you have removed/commented the page tracking call from your original analytics implementation?

EG: //ga('send', 'pageview')

daniel-obadia commented 10 years ago

@timelf123 Thanks for your reply. Yes we've followed all the instructions correctly. The only way to stop the double page views was by adding the "$analyticsProvider.virtualPageviews(false);". Take note that we add "$analyticsProvider.api.settings.pageTracking.basePath = '/my-search';" to our "mySearch" module in order to send the correct basePath.

timelf123 commented 10 years ago

Thanks for the clarification. Can you post a minimal example of this behavior on http://plnkr.co/ so I can troubleshoot/debug?

daniel-obadia commented 9 years ago

@timelf123 Will definitely setup a plunker for you in the coming days...Just as a quick followup to this :

After some more testing and considering that we are using nested angular.modules, I set "$analyticsProvider.virtualPageviews(false);" in the main app.js file and now all nested apps dont send the double page views. Before I had this on every angular.module

luisfarzati commented 9 years ago

Closing old issues -- please feel free to reopen if you want to discuss.