How to use when script is already injected with GTM?
Closed this issue · 8 comments
Hi there,
I was looking forward to using your module with a single-page-application of ours.
However the app is integrated into a page, that already has loaded google analytics via the google tag manager.
Is it possible to somehow tell your module that the script is already existant and does not have to be loaded up again? Because I get the GA welcome trace in the Browser console twice and am not sure if that's why some things dont work as expected.
Cheers & keep up the awesome work
Have you tried delaying the tag creation as described in the README section?
AnalyticsProvider.delayScriptTag(true);
I tried this and though it only loads GA once, I get an Invalid tracking Id. Aborting hit.
error from the Google Analytics Debug Chrome extension:
This happens with both automatic page tracking and manual calls to Analytics.trackPage
.
I'm going to try to exclude Google Analytics on just the app's page via Google Tag Manager until there's a resolution. Other than that, this thing is pretty awesome.
This library isn't designed for an existing GA script to be present or that script to have configured the trackers already. It would be a bit of a refactor to change this. Not much of a refactor actually, but one none the less. We would just need to split the current script injection function into 2 parts: injectScriptTag and configureTrackers.
I ended up using Google Tag Manager's "History Event" to track page clicks as described here: http://www.simoahava.com/gtm-tips/track-url-fragments-as-pageviews/#gref
I am working on a change that separates the script tag injection from the tracker setup. This will a developer to call tracker configuration independently if tag injection has already been performed externally. I am in the process of updating and writing unit tests for this change. PR should come out in the next couple of days.
Hello all and thanks for the comments above regarding my issue.
The "delayScriptTags" kind of worked, but did not fix all issues.
We are currently producing a single-page-app that is to be included into a much larger project,
which already has the ga scripts in the page.
However it seems I cannot set the tracker name dynamically outside of the angular.config call.
Since the ga scripts get injected into the HTML after the angular is loaded, or at least parallel,
there is no way for me to ensure I have the tracker name during application config phase.
I tried "Analytics.setName(window.ga.getAll()[0].get('name'));" as opposed to AnalyticsProvider.setName, and this throws an error.
Is there currently any way to set the tracker name during runtime?
Cheers and keep up your outstanding work