-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Google Analytics Opt In
Warning
I'm deprecating this package as it requires more time, than what I can give, to keep it up-to-date so that the dependencies remain secure. My recommendation would be to read the source code and implement it in your website instead, as it should be easy enough yet secure.
The library's goal is to facilitate using an opt-in approach of cookies with Google Analytics.
Traditionally, GA will be enabled by default and at a later point it can be disabled. The issue is that user is not able to intentionally opt-in but rather needs to explicit opt-out whereas tracking has already happened.
Example:
- User visits website
- Website start tracking user
- It renders an opt-out option
- User clicks on opt-out
- Now, it disables tracking.
By using an opt-in approach, GA is disabled by default and if user wants to enable it at a later point then he can do so.
- User visits website
- Website start tracking user
- It renders an opt-in option
- User clicks on opt-in
- Now, it enables tracking.
Since Google Tag doesn't support opt-in out of the box, the library will help to achieve this user-focused UX.
gtag-opt-in requires two things:
- Google Tag library
- Cookie banner library
On one side Google Analytics must be working and on the other a banner library to show the opt-in option to the user. GTag Opt In will act as the middle man between these two. After rendering of cookie banner and user clicking opt-in, the library will enable Google Analytics.
Params: GAMeasurementID
- required - represents the value of the GA property ID.
Registers the GA property ID. Later calls from optIn
and optOut
methods will refer to this value.
Enables Google Analytics.
Follows the gtag.js documentation to establish the specified GA Measurement ID as the default Google Analytics property ID. Plus it also follows the IP anonymization with gtag.js guide for a better GDPR compliance.
Disables Google Analytics.
Follows the Disable Google Analytics measurement guide where Analytics is disabled programatically, even if it was previously enabled.
Checkout the NPM page for installation instructions.