Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove analytics tracking for non-vip sites #42

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,15 @@ For another example of how this filter can be used to extend block data, we have

## Analytics

The plugin records two data points for analytics:
**Please note that, this is for VIP sites only. Analytics is disabled if this plugin is not being run on VIP sites.**
ingeniumed marked this conversation as resolved.
Show resolved Hide resolved

1. A usage metric when the `/wp-json/vip-block-data-api` REST API is used to retrive block data. This analytic data simply is a counter, and includes no information about the post's content or metadata.
The plugin records two data points for analytics, on VIP sites:

When the plugin is used on the [WordPress VIP][wpvip] platform, analytic data will include the customer site ID associated with usage. All other usage of this plugin outside of WordPress VIP is marked with an `Unknown` source.
1. A usage metric when the `/wp-json/vip-block-data-api` REST API is used to retrive block data. This analytic data simply is a counter, and includes no information about the post's content or metadata. It will only include the customer site ID to associate the usage.

2. When an error occurs from within the plugin on the [WordPress VIP][wpvip] platform. This is used to identify issues with customers for private follow-up. All other usage of this plugin outside of WordPress VIP does not record error analytics.
2. When an error occurs from within the plugin on the [WordPress VIP][wpvip] platform. This is used to identify issues with customers for private follow-up.

Both of these data points are a counter that is incremented, and do not contain any other telemetry or sensitive data. You can see what's being [collected in code here][repo-analytics].
Both of these data points are a counter that is incremented, and do not contain any other telemetry or sensitive data. You can see what's being [collected in code here][repo-analytics], and WPVIP's privacy policy [here](https://wpvip.com/privacy/).

## Caching on WPVIP

Expand Down Expand Up @@ -1052,4 +1052,4 @@ composer run test
[wpvip-plugin-activate]: https://docs.wpvip.com/how-tos/activate-plugins-through-code/
[wpvip-plugin-submodules]: https://docs.wpvip.com/technical-references/plugins/installing-plugins-best-practices/#h-submodules
[wpvip-plugin-subtrees]: https://docs.wpvip.com/technical-references/plugins/installing-plugins-best-practices/#h-subtrees
[wpvip]: https://wpvip.com/
[wpvip]: https://wpvip.com/
45 changes: 13 additions & 32 deletions src/analytics/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public static function init() {
}

public static function record_usage() {
self::$analytics_to_send[ WPCOMVIP__BLOCK_DATA_API__STAT_NAME__USAGE ] = self::get_identifier();
// Record usage on WPVIP sites only
if ( ! self::is_wpvip_site() ) {
return;
}

self::$analytics_to_send[ WPCOMVIP__BLOCK_DATA_API__STAT_NAME__USAGE ] = constant( 'FILES_CLIENT_SITE_ID' );
}

/**
Expand All @@ -34,7 +39,7 @@ public static function record_error( $error ) {
'vip-block-data-api-no-blocks',
] );

if ( self::is_wpvip_site() && defined( 'FILES_CLIENT_SITE_ID' ) && ! $is_skippable_error_for_analytics ) {
if ( self::is_wpvip_site() && ! $is_skippable_error_for_analytics ) {
// Record error data from WPVIP for follow-up
self::$analytics_to_send[ WPCOMVIP__BLOCK_DATA_API__STAT_NAME__ERROR ] = constant( 'FILES_CLIENT_SITE_ID' );
}
Expand All @@ -53,41 +58,17 @@ public static function send_analytics() {
unset( self::$analytics_to_send[ WPCOMVIP__BLOCK_DATA_API__STAT_NAME__USAGE ] );
}

self::send_pixel( self::$analytics_to_send );
}

private static function send_pixel( $stats ) {
$query_args = [
'v' => 'wpcom-no-pv',
];

foreach ( $stats as $name => $group ) {
$query_param = rawurlencode( 'x_' . $name );
$query_value = rawurlencode( $group );

$query_args[ $query_param ] = $query_value;
}

$pixel = add_query_arg( $query_args, 'http://pixel.wp.com/b.gif' );

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
wp_remote_get( $pixel, array(
'blocking' => false,
'timeout' => 1,
) );
}

private static function get_identifier() {
if ( self::is_wpvip_site() && defined( 'FILES_CLIENT_SITE_ID' ) ) {
return constant( 'FILES_CLIENT_SITE_ID' );
} else {
return 'Unknown';
// Use the built in mu-plugins methods to send the data to VIP Stats
if ( function_exists( '\Automattic\VIP\Stats\send_pixel' ) ) {
\Automattic\VIP\Stats\send_pixel( self::$analytics_to_send );
}
}

private static function is_wpvip_site() {
return defined( 'WPCOM_IS_VIP_ENV' ) && constant( 'WPCOM_IS_VIP_ENV' ) === true
&& defined( 'WPCOM_SANDBOXED' ) && constant( 'WPCOM_SANDBOXED' ) === false;
&& defined( 'WPCOM_SANDBOXED' ) && constant( 'WPCOM_SANDBOXED' ) === false
&& defined( 'FILES_CLIENT_SITE_ID' )
&& function_exists( '\Automattic\VIP\Stats\send_pixel' );
}
}

Expand Down