angulartics / angulartics-google-analytics

Google Analytics plugin for Angulartics
MIT License
133 stars 86 forks source link

Nothing is recorded to google analytics #113

Closed craigbroadman closed 6 years ago

craigbroadman commented 6 years ago

I am using the latest version of angulartics and the latest version of angulartics-google-analytics (downloaded via bower) and it isn't recording anything to google analytics.

If however I replace the angulartics-ga.min.js script with a previous version (0.17.2) it all works ok.

What am I missing?

var module = angular.module(
            "app",
            [
                "ngAnimate",
                "ngRoute",
                "ngSanitize",
                "ngTouch",
                "ngCookies",
                // 3rd Party Modules
                "ui.bootstrap", // ui-bootstrap (ex: carousel, pagination, dialog)
                "angulartics", // plug in for analyitics http://luisfarzati.github.io/angulartics/
                "angulartics.google.analytics", // google analytics plugin for angulartics
            ]);

module.config(["$analyticsProvider", ($analyticsProvider: angulartics.IAnalyticsServiceProvider): void => {
                $analyticsProvider.withBase(true);
            }
        ]);
lucianosantana commented 6 years ago

@craigbroadman Although I don't see any version 0.17.2. I suspect that either you didn't add the Google Analytics tracker code or it's been loaded after Angulartics code. The problem is that the dispatchToGa function is defined on the module's config phase and if for any reason the GA script is not loaded yet, then it won't do any action, never. In my opinion it should try to set the function again on every new dispatchToGa call .

lucianosantana commented 6 years ago

@craigbroadman try using the unminified file from this fork I've just done and let me know if that works for you. It actually fixed the use case I have in a project, where the analytics ID is received via an API, therefore the script is lazy loaded after the API call is done.

https://github.com/lucianosantana/angulartics-google-analytics/blob/master/lib/angulartics-ga.js

Do you think it makes sense @DanWilkerson . Asking you because it touches things you've done some time ago.

If so I'll submit a PR.

DanWilkerson commented 6 years ago

Go ahead and submit a PR and I'll take a look; definitely not a bad idea, and how I would have done it if I were here when the project started.

lucianosantana commented 6 years ago

@DanWilkerson here is the PR https://github.com/angulartics/angulartics-google-analytics/pull/114 I've noticed there are some CI errors due to npm warning. Unrelated to the change I've made. In any case I'd say this should be fixed in a separate PR.

DanWilkerson commented 6 years ago

Thanks for the PR!