Last active
August 25, 2021 17:02
-
-
Save felixarntz/2800ed9abfa13aabfa6e5c8ba9ec5066 to your computer and use it in GitHub Desktop.
WordPress mini plugin as an extension to Site Kit that ensures the inserted Google Analytics snippet anonymizes IP addresses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Site Kit by Google Anonymize IPs plugin file. | |
* | |
* @package Google\Site_Kit_Anomyize_IPs | |
* @author Felix Arntz, Google | |
* @license GPL-2.0-or-later | |
* @copyright 2019 Google Inc. | |
* | |
* @wordpress-plugin | |
* Plugin Name: Site Kit by Google Anonymize IPs | |
* Description: Ensures the inserted Google Analytics snippet anonymizes IP addresses. | |
* Plugin URI: https://gist.github.com/felixarntz/2800ed9abfa13aabfa6e5c8ba9ec5066 | |
* Version: 0.1.0 | |
* Author: Felix Arntz, Google | |
* Author URI: https://felix-arntz.me | |
* License: GNU General Public License v2 (or later) | |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
namespace Google\Site_Kit_Anomyize_IPs; | |
/* | |
* We only need to filter Analytics options for non-AMP, since in AMP (the filter would be 'googlesitekit_amp_gtag_opt') anonymizing IPs is enabled by default | |
* (see https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/0.1/vendors/gtag.js#L50). | |
*/ | |
add_filter( | |
'googlesitekit_gtag_opt', | |
function( array $options ) { | |
// See https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization. | |
$options['anonymize_ip'] = true; | |
return $options; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment