-
Notifications
You must be signed in to change notification settings - Fork 330
Description
The default GA snippet implementation doesn't add the option to anonymise IP addresses, which is required in some countries, for example the EU.
For all cases where Site Kit places the GA snippet on behalf of the user, we should enable this by default. (Site Kit can't update the snippet for sites where it was already placed via another plugin or other method.)
Steps to QA
Ensure the functionality in the AC/IB works, but it's worth additional QA on an existing site that upgrades to this functionality, because it introduces a new setting with a default.
- Create/use an existing site with Analytics enabled before updating to a version of the plugin with this commit.
- Ensure the HTML/analytics tag output does not include
"anonymize_ip":true - Update the version of the plugin to one with this change.
- Check the HTML source; it should now include
"anonymize_ip":true
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
For cases where there is no pre-existing GA snippet detected on the site and the user decides to let Site Kit place the GA snippet on their behalf, check if the site is primary AMP.
- If yes, no need for further action.
- If not:
- When placing the snippet, add the
anonymize_ipparameter to anonymise IP addresses (details here) - In the Analytics settings section, add a toggle (on by default) with the text "Anonymise IP address".
- When placing the snippet, add the
Implementation Brief
- Add a toggle (on by default) to enable "Anonymize IP" functionality in
assets/js/modules/analytics/setup.jswith the text:
<Switch label={ __( 'Anonymize IP Address', 'google-site-kit' ) } />
<p>{ __( 'IP addresses will be anonymized.', 'google-site-kit' ) }</p>- The above switch should only be available on the change/edit screens—not during setup.
- Add a setting to the
Modules/Analytics.phpcode for anonymizing IP addresses. This should be enabled by default on updates to respect GDPR—existing users will have the feature on-by-default like new users would. - If the anonymous IP setting is enabled, add to
enqueue_gtag_jsinModules/Analytics.php.
$anonymize_ip_address = $this->get_data( 'anonymize-ip-address' );
if ( ! is_wp_error( $anonymize_ip_address ) && $anonymize_ip_address ) {
// See https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization.
$gtag_opt['anonymize_ip'] = true;
}Changelog entry
- Anonymize IP addresses by default in Google Analytics snippet, and grant the user control to modify with a new setting.
