Support configuring ePrivacy Mode

This commit is contained in:
Jarek Rozanski 2022-01-24 00:09:38 +01:00
parent 203d63a5d0
commit 1a4faa079d
6 changed files with 55 additions and 8 deletions

View file

@ -4,7 +4,7 @@ Tags: web analytics, tracking, web traffic, analytics, statistics, stats
Requires at least: 5.2
Tested up to: 5.8.2
Requires PHP: 7.2
Stable tag: 1.0.5
Stable tag: 1.0.6
License: GPLv2
Easily add Wide Angle Analytics tracker script to your WordPress site. You can quickly configure your web analytics tracker script.

View file

@ -3,18 +3,20 @@ class WideAngleAttributes {
public $siteId;
public $ignoreHash;
public $fingerprint;
public $ePrivacyMode;
public $trackerDomain;
public $exclusionString;
public $includeParamsString;
private $helpers;
public function __construct($siteId, $trackerDomain, $ignoreHash, $exclusionString, $includeParamsString, $fingerprint) {
public function __construct($siteId, $trackerDomain, $ignoreHash, $exclusionString, $includeParamsString, $fingerprint, $ePrivacyMode) {
$this->siteId = $siteId;
$this->trackerDomain = $trackerDomain;
$this->ignoreHash = $ignoreHash;
$this->exclusionString = $exclusionString;
$this->includeParamsString = $includeParamsString;
$this->fingerprint = $fingerprint;
$this->ePrivacyMode = $ePrivacyMode;
$this->helpers = new WideAngleHelpers();
}
@ -24,6 +26,7 @@ class WideAngleAttributes {
'tracker_domain' => $this->trackerDomain,
'ignore_hash' => $this->ignoreHash,
'fingerprint' => $this->fingerprint,
'eprivacy_mode' => $this->ePrivacyMode,
'exclusion_paths' => $this->generateExclusionsAttribute(),
'include_params' => $this->generateIncludeParamsAttribute()
);

View file

@ -6,6 +6,7 @@ class WideAngleGenerator {
public $trackerDomain;
public $exclusionPaths;
public $includeParams;
public $ePrivacyMode;
public function __construct($attributes) {
$this->siteId = $attributes['site_id'];
@ -14,6 +15,7 @@ class WideAngleGenerator {
$this->exclusionPaths = $attributes['exclusion_paths'];
$this->includeParams = $attributes['include_params'];
$this->fingerprint = $attributes['fingerprint'];
$this->ePrivacyMode = $attributes['eprivacy_mode'];
}
@ -31,10 +33,12 @@ EOD;
$includeParamsAttribute = $this->includeParams != '' ? "data-waa-inc-params=\"" . esc_attr($this->includeParams) . "\"": '';
$ignoreHashAttribute = $this->ignoreHash != '' ? "data-waa-ignore-hash=\"" . esc_attr($this->ignoreHash) . "\"": 'data-waa-ignore-hash="false"';
$fingerprintAttribute = $this->fingerprint != '' ? "data-waa-fingerprint=\"" . esc_attr($this->fingerprint) . "\"": '';
$ePrivacyModeAttribute = $this->ePrivacyMode == 'consent' ? "data-waa-eprivacy-mode=\"" . esc_attr($this->ePrivacyMode) . "\"": '';
$script = <<<EOD
<script async defer
src="{$trackerUrlAttribute}"
$fingerprintAttribute
$ePrivacyModeAttribute
$ignoreHashAttribute
$includeParamsAttribute
$pathExlusionsAttribute></script>

View file

@ -37,6 +37,14 @@ class WideAngleHelpers {
}
}
function validateEPrivacyMode($name, $ePrivacyMode) {
if($ePrivacyMode === 'consent') {
return WideAngleValidated::createValid($name, $ePrivacyMode, "consent");
} else {
return WideAngleValidated::createValid($name, $ePrivacyMode, "disabled");
}
}
function validateSiteId($name, $siteId) {
if(preg_match("/^[a-zA-Z0-9]{10,24}$/", $siteId)) {
return WideAngleValidated::createValid($name, $siteId, strtoupper(trim($siteId)));

View file

@ -3,6 +3,7 @@ $siteId = wp_unslash($this->settings[self::WAA_CONF_SITE_ID]);
$trackerDomain = wp_unslash($this->settings[self::WAA_CONF_TRACKER_DOMAIN]);
$ignoreHash = filter_var($this->settings[self::WAA_CONF_IGNORE_HASH], FILTER_VALIDATE_BOOLEAN);
$fingerprint = filter_var($this->settings[self::WAA_CONF_FINGERPRINT], FILTER_VALIDATE_BOOLEAN);
$ePrivacyMode = wp_unslash($this->settings[self::WAA_CONF_EPRIVACY_MODE]);
$parsedExclusions = $this->plugin->helpers->parseExclusionSetting(wp_unslash($this->settings[self::WAA_CONF_EXC_PATHS]));
$parsedIncludeParams = $this->plugin->helpers->parseIncludeParamsSetting(wp_unslash($this->settings[self::WAA_CONF_INC_PARAMS]));
$generator = new WideAngleGenerator($this->settings[self::WAA_CONF_ATTRIBUTES]);
@ -138,6 +139,26 @@ $generator = new WideAngleGenerator($this->settings[self::WAA_CONF_AT
<p class="description" id="tagline-description">The tracker script will <b>not</b> attempt to fingerprint the browser by default. You can improve tracking qaulity by enabling more reliable browser fingerprinting. Enabling this feature might require collecting consent.</p>
</td>
</tr>
<tr>
<th scope="row"><label>ePrivacyMode</label></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Browser Fingerprinting</span></legend>
<label>
<select name="waa_eprivacy_mode" id="waa_eprivacy_mode">
<?php
foreach($this->plugin->ePrivacyModes as $id => $label) {
?>
<option value="<?php echo esc_attr($id); ?>"<?php if($ePrivacyMode == $id) echo ' selected'; ?>><?php echo esc_html($label); ?></option>
<?php
}
?>
</select>
</label>
</fieldset>
<p class="description" id="tagline-description">When you disable tracking, the script collects only bare-bone information. You can opt for more verbose tracking, but be aware that according to ePrivacy Regulations, this might require visitor's consent.</p>
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( $this->plugin->name, $this->plugin->name . '_nonce' ); ?>

View file

@ -5,7 +5,7 @@
Description: Easily enable and configure Wide Angle Analytics on your Wordpress site
Author: Wide Angle Analytics by Input Objects GmbH
Author URI: https://wideangle.co
Version: 1.0.5
Version: 1.0.6
Requires at least: 5.2
Requires PHP: 7.2
License: GPL v2
@ -18,6 +18,7 @@ class WideAngleAnalytics {
const WAA_CONF_SITE_ID = "waa_site_id";
const WAA_CONF_TRACKER_DOMAIN = "waa_tracker_domain";
const WAA_CONF_FINGERPRINT = "waa_fingerprint";
const WAA_CONF_EPRIVACY_MODE = "waa_eprivacy_mode";
const WAA_CONF_EXC_PATHS = "waa_exc_path";
const WAA_CONF_INC_PARAMS = "waa_inc_params";
const WAA_CONF_IGNORE_HASH = "waa_ignore_hash";
@ -38,6 +39,11 @@ class WideAngleAnalytics {
"regex" => "RegEx",
);
$this->plugin->ePrivacyModes = array(
"disabled" => "Disable Tracking",
"consent" => "Track assuming consent"
);
add_action('admin_init', array( &$this, 'registerPluginSettings' ) );
add_action('admin_menu', array( &$this, 'registerAdminMenu' ));
@ -117,6 +123,7 @@ class WideAngleAnalytics {
$waaTrackerDomain = $this->plugin->helpers->validateTrackerDomain(self::WAA_CONF_TRACKER_DOMAIN, sanitize_text_field($_REQUEST['waa_tracker_domain']));
$waaIgnoreHash = $this->plugin->helpers->validateIgnoreHashFlag(self::WAA_CONF_IGNORE_HASH, sanitize_text_field($_REQUEST['waa_ignore_hash']));
$waaFingerprint = $this->plugin->helpers->validateFingerprint(self::WAA_CONF_FINGERPRINT, sanitize_text_field($_REQUEST['waa_fingerprint']));
$waaEPrivacyMode = $this->plugin->helpers->validateEPrivacyMode(self::WAA_CONF_EPRIVACY_MODE, sanitize_text_field($_REQUEST['waa_eprivacy_mode']));
$waaIncParams = $this->plugin->helpers->validateIncludeParams(self::WAA_CONF_INC_PARAMS, $_REQUEST);
$waaExclusionPaths = $this->plugin->helpers->validateExclusionPathsRequest(self::WAA_CONF_EXC_PATHS, $_REQUEST);
@ -136,7 +143,8 @@ class WideAngleAnalytics {
$waaIgnoreHash->get_value(),
$waaExclusionPaths->get_value(),
$waaIncParams->get_value(),
$waaFingerprint->get_value()
$waaFingerprint->get_value(),
$waaEPrivacyMode->get_value()
);
update_option(self::WAA_CONF_SITE_ID, $waaSiteId->get_value());
update_option(self::WAA_CONF_TRACKER_DOMAIN, $waaTrackerDomain->get_value());
@ -144,6 +152,7 @@ class WideAngleAnalytics {
update_option(self::WAA_CONF_EXC_PATHS, $waaExclusionPaths->get_value());
update_option(self::WAA_CONF_INC_PARAMS, $waaIncParams->get_value());
update_option(self::WAA_CONF_FINGERPRINT, $waaFingerprint->get_value());
update_option(self::WAA_CONF_EPRIVACY_MODE, $waaEPrivacyMode->get_value());
update_option(self::WAA_CONF_ATTRIBUTES, $attributes->generateAttributes());
$this->message = __('Settings updated', $this->plugin->name);
} else {
@ -158,6 +167,7 @@ class WideAngleAnalytics {
self::WAA_CONF_TRACKER_DOMAIN => get_option(self::WAA_CONF_TRACKER_DOMAIN),
self::WAA_CONF_IGNORE_HASH => get_option(self::WAA_CONF_IGNORE_HASH),
self::WAA_CONF_FINGERPRINT => get_option(self::WAA_CONF_FINGERPRINT),
self::WAA_CONF_EPRIVACY_MODE => get_option(self::WAA_CONF_EPRIVACY_MODE),
self::WAA_CONF_ATTRIBUTES => get_option(self::WAA_CONF_ATTRIBUTES)
);
include_once( $this->plugin->folder . '/views/admin_settings.php' );
@ -182,6 +192,7 @@ class WideAngleAnalytics {
register_setting($this->plugin->name, self::WAA_CONF_TRACKER_DOMAIN, array('default' => 'stats.wideangle.co'));
register_setting($this->plugin->name, self::WAA_CONF_IGNORE_HASH, array('default' => 'false'));
register_setting($this->plugin->name, self::WAA_CONF_FINGERPRINT, array('default' => 'false'));
register_setting($this->plugin->name, self::WAA_CONF_EPRIVACY_MODE, array('default' => 'disabled'));
register_setting($this->plugin->name, self::WAA_CONF_ATTRIBUTES, array('type' => 'array'));
}