Closed codeofsumit closed 4 years ago
I tried to call bootstrap()
but no pageview is sent when calling it 🤔
Stumbled across same issue. Looked at the API source and verified it with MatteoGabriele's reply to How to opt out after opt in
Simply calling this.$gtag.optIn()
within my component method just worked.
@hennzen just tried it again. When I call this.$gtag.optIn();
I don't see any "collect" event sent in my network tab that is normally sent when I navigate/load the page.
These events:
Is there one firing for you when you call optIn()
?
For me, the collect request only fires on first event (custom, pageview...) after calling optIn()
(vs. upon calling it)
If that still doesn't work, try getting more insight with Google Analytics Debugger Chrome Extension
@hennzen that's what I mean.
User enters page. No event.
User clicks button -> optIn()
First Event fired
User navigates page
Subsequent events are fired
The bold marked event is not happening for me.
Just installed the analytics debugger extension.
This is what happens on page load when loading vue-gtag with enabled: false
.
When I call this.$gtag.optIn()
, nothing happens. No logs are added.
Cannot reproduce. I get same output using { enabled: false }
on load, i.e. all events are being labeled "User has opted out of tracking. Aborting hit." Then calling optIn()
(no output on this one - but what about console.log()
'ing something, so you know it was called). Subsequent events being tracked and shown by the extension as expected.
Well ok then we have the same behaviour.
The problem is that optIn()
should send the first pageview immediately(!) IMO. Without navigating anywhere.
Subsequent navigation is tracked fine. I'm only concerned about the first event after calling optIn()
.
I would not expect such behaviour.
But you could nevertheless manually/programmatically trigger a pageview event after calling optIn()
to make the current pageview count
Hm ok. Then how do you track referal pages or time spent on a landing page if tracking won't start until the user navigates again? Especially Referal pages seem to be completely useless then - or am I wrong here?
sorry for the late response. The optIn method it's just changing a global variable inside the gtag global object: there's no need to fire any events, it's not something that needs to be registered. after the global variable it's re-enabled again, then you need to do something to start triggering events again: it's a simple on/off switch built-in inside google analytics or google gtag, same pattern
window['ga-disable-MY_DOMAIN_ID'] = true/false;
you can read more here https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out
the library will basically fire events and abort them at the same time, as soon as you enable it again, those events will not be aborted anymore and you will register events in your dashboard
@MatteoGabriele thanks for chiming in and taking the time to explain this. I understand now. Seems like my expectations are wrong. If this is as designed, it's more like that this is correct and my assumption that e.g. referrals aren't properly tracked is wrong.
Thanks also @hennzen ❤️
@codeofsumit you're welcome. sorry you had to wait this long for my response. yeah this is by design from Google, not from me. I can't really predict what you want to do after re-enabling the property so you might need to trigger whatever you need by yourself manually. after that, whatever happens will be picked up again by the library
Matteo, first of all thanks a lot for this awesome plugin!
I'm building a cookie banner and as per the documentation I can see how I can load the plugin with
enabled: false
. What is missing from the docs is how to actually enable it again after user consent - including sending the first pageview.Can you point me into the right direction?
Thanks in advance - all the best, Sumit