Wide Angle Analytics WordPress plugin 1.0.0 submitted for review
This commit is contained in:
commit
25f3879ece
16 changed files with 698 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/data
|
||||
/wordpress
|
||||
**/*.log
|
25
README.md
Normal file
25
README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
# WordPress Plugin for Wide Angle Analytics
|
||||
|
||||
Easily add [Wide Angle Analytics](https://wideangle.co) tracker script to your WordPress site. You can quickly configure your web analytics tracker script.
|
||||
|
||||

|
||||
|
||||
|
||||
* Requires at least: 5.2
|
||||
* Tested up to: 5.8.2
|
||||
* Requires PHP: 7.4
|
||||
|
||||
|
||||
**Wide Angle Analytics** 📈 is a privacy-friendly, GDPR-compliant web analytics service. You can deploy it cookieless or with cookies enabled.
|
||||
|
||||
We promote remote configuration, meaning you configure the tracker behaviour directly from our service interface. However, to give you full control, some settings must be applied before initial communication with our service takes place.
|
||||
|
||||
We provide you with the ability to configure the tracker script with few settings, making sure that you are tracking your traffic effectively. At the same time, we give you tools to prevent leaking any or unintended Personal Data.
|
||||
|
||||
Our plugin offers you as easy to use configuration wizard. The plugin will automatically inject the necessary HTML to both Header and Footer to make the script record website visits.
|
||||
|
||||

|
||||
|
||||
## License
|
||||
|
||||
Licensed under [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html).
|
1
docker-compose.yaml
Symbolic link
1
docker-compose.yaml
Symbolic link
|
@ -0,0 +1 @@
|
|||
docker/docker-compose.yaml
|
29
docker/docker-compose.yaml
Normal file
29
docker/docker-compose.yaml
Normal file
|
@ -0,0 +1,29 @@
|
|||
version: '3.3'
|
||||
services:
|
||||
db:
|
||||
container_name: 'local-wordpress-db'
|
||||
image: 'mysql:5.7'
|
||||
volumes:
|
||||
- './data/mysql:/var/lib/mysql'
|
||||
ports:
|
||||
- 18766:3306
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: somewordpress
|
||||
MYSQL_DATABASE: wordpress_db
|
||||
MYSQL_USER: wordpress_user
|
||||
MYSQL_PASSWORD: wordpress_password
|
||||
wordpress:
|
||||
container_name: 'local-wordpress'
|
||||
depends_on:
|
||||
- db
|
||||
image: 'wordpress:latest'
|
||||
ports:
|
||||
- '8080:80'
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: 'db:3306'
|
||||
WORDPRESS_DB_USER: wordpress_user
|
||||
WORDPRESS_DB_PASSWORD: wordpress_password
|
||||
WORDPRESS_DB_NAME: wordpress_db
|
||||
volumes:
|
||||
- "./wordpress:/var/www/html"
|
||||
- "./plugins:/var/www/html/wp-content/plugins"
|
BIN
plugins/wide-angle-analytics/assets/banner-1544x500.png
Executable file
BIN
plugins/wide-angle-analytics/assets/banner-1544x500.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
BIN
plugins/wide-angle-analytics/assets/banner-772x250.png
Executable file
BIN
plugins/wide-angle-analytics/assets/banner-772x250.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
plugins/wide-angle-analytics/assets/icon-128x128.png
Executable file
BIN
plugins/wide-angle-analytics/assets/icon-128x128.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
plugins/wide-angle-analytics/assets/icon-256x256.png
Executable file
BIN
plugins/wide-angle-analytics/assets/icon-256x256.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
1
plugins/wide-angle-analytics/assets/icon.svg
Executable file
1
plugins/wide-angle-analytics/assets/icon.svg
Executable file
|
@ -0,0 +1 @@
|
|||
<svg id="ef75b12b-5219-4a6d-87aa-497443e93c01" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><defs><style>.aef498b0-a2bd-47dd-bd96-eecddec0827e{fill:#f1f0f7;}.aef498b0-a2bd-47dd-bd96-eecddec0827e,.e775765a-64a2-4132-9ab8-d030ab2eee5a,.f02d3497-6f71-4046-8003-34f296dc09b6,.fb9d6fa9-9ead-4c19-ac33-b35fc371f714{fill-rule:evenodd;}.e775765a-64a2-4132-9ab8-d030ab2eee5a{fill:#0a0079;}.f02d3497-6f71-4046-8003-34f296dc09b6{fill:#cc0079;}.fb9d6fa9-9ead-4c19-ac33-b35fc371f714{fill:#ff9565;}</style></defs><polygon id="f78a0025-b056-4faf-90ac-d6fe52aea3c3" data-name="Fill-1" class="aef498b0-a2bd-47dd-bd96-eecddec0827e" points="0 256 256 256 256 0 0 0 0 256"/><path id="af0401d5-6133-407e-8e96-893346d98cdb" data-name="Fill-202" class="e775765a-64a2-4132-9ab8-d030ab2eee5a" d="M128,128A82,82,0,0,1,46,46h82Z" transform="translate(0 0)"/><path id="ba99ece5-9d6d-4bd7-84a4-db8bb79fbeb5" data-name="Fill-203" class="e775765a-64a2-4132-9ab8-d030ab2eee5a" d="M210,128a82,82,0,0,1-82-82h82Z" transform="translate(0 0)"/><path id="a81f1ace-cd31-4bfd-9a1c-7f05e1408e8d" data-name="Fill-204" class="f02d3497-6f71-4046-8003-34f296dc09b6" d="M46,210a82,82,0,0,1,82-82v82Z" transform="translate(0 0)"/><path id="a431a79f-898d-4efe-8327-ad2f273d8d95" data-name="Fill-205" class="fb9d6fa9-9ead-4c19-ac33-b35fc371f714" d="M128,210a82,82,0,0,1,82-82v82Z" transform="translate(0 0)"/></svg>
|
After Width: | Height: | Size: 1.4 KiB |
BIN
plugins/wide-angle-analytics/assets/screenshot-1.jpg
Normal file
BIN
plugins/wide-angle-analytics/assets/screenshot-1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 133 KiB |
30
plugins/wide-angle-analytics/readme.txt
Normal file
30
plugins/wide-angle-analytics/readme.txt
Normal file
|
@ -0,0 +1,30 @@
|
|||
=== Wide Angle Analytics ===
|
||||
Contributors: jrozanski,inputobjects
|
||||
Tags: web analytics, tracking, web traffic, analytics
|
||||
Requires at least: 5.2
|
||||
Tested up to: 5.8.2
|
||||
Requires PHP: 7.4
|
||||
Stable tag: trunk
|
||||
License: GPLv2
|
||||
|
||||
Easily add Wide Angle Analytics tracker script to your WordPress site. You can quickly configure your web analytics tracker script.
|
||||
|
||||
== Description ==
|
||||
<a href="https://wideangle.co" target="_blank">Wide Angle Analytics</a> is a privacy-friendly, GDPR-compliant web analytics service. You can deploy it cookieless or with cookies enabled.
|
||||
|
||||
We promote remote configuration, meaning you configure the tracker behaviour directly from our service interface. However, to give you full control, some settings must be applied before initial communication with our service takes place.
|
||||
|
||||
We provide you with the ability to configure the tracker script with few settings, making sure that you are tracking your traffic effectively. At the same time, we give you tools to prevent leaking any or unintended Personal Data.
|
||||
|
||||
Our plugin offers you as easy to use configuration wizard. The plugin will automatically inject the necessary HTML to both Header and Footer to make the script record website visits.
|
||||
|
||||
== Screenshots ==
|
||||
1. Configuration Wizard in Settings
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
= Do I need Wide Angle Analytics account? =
|
||||
|
||||
Yes. To start using tracking code, you will need a valid Site ID. The Site ID is available in Wide Angle Analytics Site Settings panel.
|
||||
|
||||
= Where can I find detailed documentation about Wide Angle Analytics? =
|
||||
You will find most of your answers in the <a href="https://wideangle.co/documentation">Knowledge Base</a>. Should you require further assistance, please <a href="https://wideangle.co/support">get in touch</a> with our team.
|
80
plugins/wide-angle-analytics/types/WideAngleConfig.php
Normal file
80
plugins/wide-angle-analytics/types/WideAngleConfig.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
class WideAngleConfig {
|
||||
public $siteId;
|
||||
public $ignoreHash;
|
||||
public $trackerDomain;
|
||||
public $exclusionString;
|
||||
public $includeParamsString;
|
||||
private $helpers;
|
||||
|
||||
public function __construct($siteId, $trackerDomain, $ignoreHash, $exclusionString, $includeParamsString) {
|
||||
$this->siteId = $siteId;
|
||||
$this->trackerDomain = $trackerDomain;
|
||||
$this->ignoreHash = $ignoreHash;
|
||||
$this->exclusionString = $exclusionString;
|
||||
$this->includeParamsString = $includeParamsString;
|
||||
$this->helpers = new WideAngleHelpers();
|
||||
}
|
||||
|
||||
function generateHeaderScript() {
|
||||
$script = <<<EOD
|
||||
<link href="{$this->trackerDomain}/script/{$this->siteId}.js" ref="prefetch"/>
|
||||
EOD;
|
||||
return $script;
|
||||
}
|
||||
|
||||
function generateFooterScript() {
|
||||
$pathExlusionsAttribute = $this->generateExclusionsAttribute();
|
||||
$includeParamsAttribute = $this->generateIncludeParamsAttribute();
|
||||
|
||||
$script = <<<EOD
|
||||
<script async defer
|
||||
src="{$this->trackerDomain}/script/{$this->siteId}.js"
|
||||
data-waa-ignore-hash="{$this->ignoreHash}"
|
||||
$includeParamsAttribute
|
||||
$pathExlusionsAttribute></script>
|
||||
EOD;
|
||||
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $script);
|
||||
}
|
||||
|
||||
private function generateIncludeParamsAttribute() {
|
||||
$params = $this->helpers->parseIncludeParamsSetting($this->includeParamsString);
|
||||
if(sizeof($params) > 0) {
|
||||
return "data-waa-inc-params=\"" . implode(",", $params) . "\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private function generateExclusionsAttribute() {
|
||||
$pathExlusionsAttribute = "";
|
||||
$exclusions = $this->helpers->parseExclusionSetting($this->exclusionString);
|
||||
if(sizeof($exclusions) > 0) {
|
||||
$pathExlusionsAttribute = $this->generateExclusionsAttributeValue($exclusions);
|
||||
}
|
||||
|
||||
$pathExlusionsAttributeWithKey = "";
|
||||
if(trim($pathExlusionsAttribute) != "") {
|
||||
$pathExlusionsAttributeWithKey = "data-waa-exc-paths=\"" . $pathExlusionsAttribute ."\"";
|
||||
}
|
||||
return $pathExlusionsAttributeWithKey;
|
||||
}
|
||||
|
||||
private function generateExclusionsAttributeValue($exclusions) {
|
||||
$accumulator = array();
|
||||
foreach($exclusions as $exclusion) {
|
||||
switch($exclusion->get_type()) {
|
||||
case "start":
|
||||
array_push($accumulator, "^" . preg_quote($exclusion->get_value()) . ".*");
|
||||
break;
|
||||
case "end":
|
||||
array_push($accumulator, ".*" . preg_quote($exclusion->get_value()) . "$");
|
||||
break;
|
||||
case "regex":
|
||||
array_push($accumulator, $exclusion->get_value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return implode(",", $accumulator);
|
||||
}
|
||||
}
|
||||
?>
|
21
plugins/wide-angle-analytics/types/WideAngleExclusion.php
Normal file
21
plugins/wide-angle-analytics/types/WideAngleExclusion.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
class WideAngleExclusion {
|
||||
public $type;
|
||||
public $value;
|
||||
|
||||
public function __construct($type, $value) {
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function get_type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function get_value() {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
78
plugins/wide-angle-analytics/types/WideAngleHelpers.php
Normal file
78
plugins/wide-angle-analytics/types/WideAngleHelpers.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
include_once( $this->plugin->folder . '/types/WideAngleExclusion.php' );
|
||||
|
||||
class WideAngleHelpers {
|
||||
|
||||
|
||||
|
||||
function normalizeBoolean($value) {
|
||||
$trimmed = trim($value);
|
||||
switch($trimmed) {
|
||||
case "":
|
||||
case "false":
|
||||
case "off":
|
||||
return "false";
|
||||
case "on":
|
||||
case "true":
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTrackerDomain($domain) {
|
||||
return "https://" . parse_url($domain, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
function parseIncludeParamsSetting($params) {
|
||||
if(trim($params) !== "") {
|
||||
return preg_split("/\|\:/", $params);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
function parseRequestIncludeParams($request) {
|
||||
$pattern = "/^waa_inc_params_(\d{1,2})$/";
|
||||
$params = array();
|
||||
foreach($request as $key => $value) {
|
||||
if(preg_match($pattern, $key)) {
|
||||
array_push($params, trim($value));
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
function parseExclusionSetting($path) {
|
||||
$flatExclusions = $path;
|
||||
$exclusions = preg_split("/\|\:/", $flatExclusions);
|
||||
$exclusionPattern = '/^\[([A-Za-z0-9]{1,10})\](.*)$/';
|
||||
$matches = array();
|
||||
$parsedExclusions = array();
|
||||
|
||||
|
||||
foreach($exclusions as $exclusion) {
|
||||
if(preg_match($exclusionPattern, $exclusion, $matches) > 0) {
|
||||
array_push($parsedExclusions, new WideAngleExclusion($matches[1], $matches[2]));
|
||||
}
|
||||
}
|
||||
return $parsedExclusions;
|
||||
}
|
||||
|
||||
function parseRequestExclusionPaths($request) {
|
||||
$pattern = "/^waa_exc_path_(\d{1,2})_type$/";
|
||||
$exclusions = array();
|
||||
foreach($request as $key => $exclusionType) {
|
||||
$idx = array();
|
||||
if(preg_match($pattern, $key, $idx)) {
|
||||
$valueKey = "waa_exc_path_".$idx[1]."_value";
|
||||
$exclusionValue = trim($request[$valueKey]);
|
||||
if($exclusionValue != null && $exclusionValue != "") {
|
||||
$typedExclusion = "[" . $exclusionType . "]" .$exclusionValue;
|
||||
array_push($exclusions, $typedExclusion);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $exclusions;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
241
plugins/wide-angle-analytics/views/admin_settings.php
Normal file
241
plugins/wide-angle-analytics/views/admin_settings.php
Normal file
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
$siteId = $this->settings[self::WAA_CONF_SITE_ID];
|
||||
$trackerDomain = $this->settings[self::WAA_CONF_TRACKER_DOMAIN];
|
||||
$ignoreHash = filter_var($this->settings[self::WAA_CONF_IGNORE_HASH], FILTER_VALIDATE_BOOLEAN);
|
||||
$parsedExclusions = $this->plugin->helpers->parseExclusionSetting($this->settings[self::WAA_CONF_EXC_PATHS]);
|
||||
$parsedIncludeParams = $this->plugin->helpers->parseIncludeParamsSetting($this->settings[self::WAA_CONF_INC_PARAMS]);
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2>
|
||||
<?php echo $this->plugin->displayName; ?> » <?php esc_html_e( 'Settings', 'wide-angle-analytics' ); ?>
|
||||
</h2>
|
||||
|
||||
<div>
|
||||
<h3>Configure your Wide Angle Analytics tracker script</h3>
|
||||
<details>
|
||||
<summary>Need help?</summary>
|
||||
<p>Our <a href="https://wideangle.co/documentation">documentation</a> has dedicated section about:
|
||||
<ul class="ul-disc">
|
||||
<li><a href="https://wideangle.co/documentation/create-and-configure-site" target="_blank">Creating New Site</a></li>
|
||||
<li><a href="https://wideangle.co/documentation/configure-site" target="_blank">Site Configuration and Meaning of Specific Options</a></li>
|
||||
<li><a href="https://wideangle.co/documentation/track-with-custom-domain" target="_blank">Creating Custom Tracker Domain</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ( isset( $this->message ) ) {
|
||||
?>
|
||||
<div class="updated fade"><p><?php echo $this->message; ?></p></div>
|
||||
<?php
|
||||
}
|
||||
if ( isset( $this->errorMessage ) ) {
|
||||
?>
|
||||
<div class="error fade"><p><?php echo $this->errorMessage; ?></p></div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<form action="options-general.php?page=<?php echo $this->plugin->name; ?>" method="post">
|
||||
<table class="form-table" role="presentation">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label>Site ID</label></th>
|
||||
<td>
|
||||
<input id="waa_site_id" type="text" name="waa_site_id" pattern="[A-Z0-9]{10,24}" class="regular-text" value="<?php echo $siteId ?>"/>
|
||||
<p class="description" id="tagline-description">A Site ID. You will find it in the Site Settings, in Wide Angle Analytics Dashboard.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label>Tracker Domain</label></th>
|
||||
<td>
|
||||
<input id="waa_tracker_domain" type="url" name="waa_tracker_domain" class="regular-text code" value="<?php echo $trackerDomain ?>"/>
|
||||
<p class="description" id="tagline-description">A domain you selected for your tracker. You can check current domain in the Site Settings, in the Wide Angle Analytics. If you haven't set custom domain for your site, there is no need to change this field.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label>Excluded Paths</label></th>
|
||||
<td>
|
||||
<div data-waa-exc-path="exclusion_container">
|
||||
<?php
|
||||
for($i = 0; $i < sizeof($parsedExclusions); $i++) {
|
||||
$exclusion = $parsedExclusions[$i];
|
||||
?>
|
||||
<div data-waa-exc-path="<?php echo $i; ?>" style="display: flex; flex-direction: row; margin-bottom: 0.3rem">
|
||||
<select name="waa_exc_path_<?php echo $i; ?>_type" id="waa_exc_path_<?php echo $i; ?>_type">
|
||||
<?php
|
||||
foreach($this->plugin->exclusionTypes as $id => $label) {
|
||||
?>
|
||||
<option value="<?php echo $id ?>"<?php if($exclusion->get_type() == $id) echo ' selected'; ?>><?php echo $label ?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<option value="end"<?php if($exclusion->get_type() == "end") echo ' selected'; ?>>Ends with</option>
|
||||
<option value="regex"<?php if($exclusion->get_type() == "regex") echo ' selected'; ?>>RegEx</option>
|
||||
</select>
|
||||
<input type="text" name="waa_exc_path_<?php echo $i; ?>_value" value="<?php echo $exclusion->get_value(); ?>"/>
|
||||
<button data-waa-action="remove_exclusion" data-waa-exc-path="<?php echo $i; ?>" class="button button-secondary">Remove</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<button id="add_exclusion" class="button button-secondary" style="margin-top: 0.5rem;">Add</button>
|
||||
<p class="description" id="tagline-description">A list of URL patterns you would like to exclude from tracking.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label>List of additional parameters</label></th>
|
||||
<td>
|
||||
<div data-waa-inc-params="params_container">
|
||||
<?php
|
||||
for($i = 0; $i < sizeof($parsedIncludeParams); $i++) {
|
||||
$param = $parsedIncludeParams[$i];
|
||||
?>
|
||||
<div data-waa-inc-params="<?php echo $i; ?>" style="display: flex; flex-direction: row; margin-bottom: 0.3rem">
|
||||
<input type="text" name="waa_inc_params_<?php echo $i; ?>" value="<?php echo $param; ?>" pattern="[A-Za-z0-9_-]{1,128}"/>
|
||||
<button data-waa-action="remove_param" data-waa-inc-params="<?php echo $i; ?>" class="button button-secondary">Remove</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<button id="add_param" class="button button-secondary" style="margin-top: 0.5rem;">Add</button>
|
||||
<p class="description" id="tagline-description">Add parameter to include when sending tracking event. By default only <code>utm_*</code> and <code>ref</code> parameters are transmitted.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label>URL Fragment</label></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><span>URL Fragment</span></legend>
|
||||
<label>
|
||||
<input id="waa_ignore_hash" type="checkbox" name="waa_ignore_hash" <?php if($ignoreHash) { echo "checked"; } ?>/> Ignore
|
||||
</label>
|
||||
</fieldset>
|
||||
<p class="description" id="tagline-description">By default, w URL Fragment/hash is trasmitted as part of the tracking event. You can disable this behaviour. The fragment will be stripped before sending an event.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php wp_nonce_field( $this->plugin->name, $this->plugin->name . '_nonce' ); ?>
|
||||
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" style="margin-right: 1rem;">Press save to generate and preview new script.
|
||||
</p>
|
||||
</form>
|
||||
<div>
|
||||
<h3>Script generated from saved settings</h3>
|
||||
<code style="background-color: inherit">
|
||||
<pre style="padding: 1rem; border: 1px solid;">
|
||||
<head>
|
||||
<!-- .. -->
|
||||
<b><?php echo $this->settings[self::WAA_CONF_GENERATED_HEADER_SCRIPT]; ?></b>
|
||||
|
||||
</head>
|
||||
<!-- .. -->
|
||||
<b><?php echo $this->settings[self::WAA_CONF_GENERATED_FOOTER_SCRIPT]; ?></b>
|
||||
</pre>
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
// Exlude Params helpers
|
||||
|
||||
var pathExclusionTemplate = '<div data-waa-exc-path="0" style="display: flex; flex-direction: row; margin-bottom: 0.3rem"><select name="waa_exc_path_0_type"><option value="start">Starts with</option><option value="end">Ends with</option><option value="regex">RegEx</option></select><input type="text" name="waa_exc_path_0_value"/><button data-waa-action="remove_exclusion" data-waa-exc-path="0" class="button button-secondary">Remove</button></div>'
|
||||
|
||||
function addNewExclusion(seq) {
|
||||
var element = jQuery("div[data-waa-exc-path] div:last-child");
|
||||
var idx = 0;
|
||||
if (element == undefined && seq) {
|
||||
idx = seq;
|
||||
} else if (element) {
|
||||
lastKnownIdx = element.attr('data-waa-exc-path');
|
||||
idx = lastKnownIdx ? parseInt(lastKnownIdx) + 1 : 0;
|
||||
}
|
||||
var elementTemplate = jQuery.parseHTML(pathExclusionTemplate)
|
||||
var copy = jQuery(elementTemplate);
|
||||
|
||||
copy.attr('data-waa-exc-path', idx)
|
||||
copy.find('select').attr('name', 'waa_exc_path_' + idx + '_type');
|
||||
copy.find('select').val("start");
|
||||
copy.find('input').attr('name', 'waa_exc_path_' + idx + '_value');
|
||||
copy.find('input').val("");
|
||||
copy.find('button').attr('data-waa-exc-path', idx);
|
||||
if(idx > 0) {
|
||||
copy.insertAfter("div[data-waa-exc-path] div:last-child")
|
||||
} else {
|
||||
copy.appendTo("div[data-waa-exc-path]")
|
||||
}
|
||||
}
|
||||
|
||||
function removeExclusion(idx) {
|
||||
var parent = jQuery("div[data-waa-exc-path]");
|
||||
jQuery(document).find('div[data-waa-exc-path="' + idx + '"]').remove();
|
||||
if(parent.children().length == 0) {
|
||||
addNewExclusion(0);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(document).on('click', "#add_exclusion", function(event) {
|
||||
event.preventDefault();
|
||||
addNewExclusion();
|
||||
});
|
||||
|
||||
jQuery(document).on('click','button[data-waa-action="remove_exclusion"]', function(event) {
|
||||
event.preventDefault();
|
||||
var idx = event.currentTarget.getAttribute('data-waa-exc-path');
|
||||
removeExclusion(idx);
|
||||
return false;
|
||||
});
|
||||
|
||||
// Include Params helpers
|
||||
|
||||
var paramIncludeTemplate = '<div data-waa-inc-params="0" style="display: flex; flex-direction: row; margin-bottom: 0.3rem"><input type="text" name="waa_inc_params_0" value="" pattern="[A-Za-z0-9_-]{1,128}"/><button data-waa-action="remove_param" data-waa-inc-params="0" class="button button-secondary">Remove</button></div>';
|
||||
|
||||
function addNewParam(seq) {
|
||||
var element = jQuery("div[data-waa-inc-params] div:last-child");
|
||||
var idx = 0;
|
||||
if (element == undefined && seq) {
|
||||
idx = seq;
|
||||
} else if (element) {
|
||||
lastKnownIdx = element.attr('data-waa-inc-params');
|
||||
idx = lastKnownIdx ? parseInt(lastKnownIdx) + 1 : 0;
|
||||
}
|
||||
var elementTemplate = jQuery.parseHTML(paramIncludeTemplate)
|
||||
var copy = jQuery(elementTemplate);
|
||||
|
||||
copy.attr('data-waa-inc-params', idx)
|
||||
copy.find('input').attr('name', 'waa_inc_params_' + idx);
|
||||
copy.find('input').val("");
|
||||
copy.find('button').attr('data-waa-inc-params', idx);
|
||||
if(idx > 0) {
|
||||
copy.insertAfter("div[data-waa-inc-params] div:last-child")
|
||||
} else {
|
||||
copy.appendTo("div[data-waa-inc-params]")
|
||||
}
|
||||
}
|
||||
|
||||
function removeParam(idx) {
|
||||
var parent = jQuery("div[data-waa-inc-params]");
|
||||
console.log('Removing div[data-waa-inc-params="' + idx + '"]');
|
||||
jQuery(document).find('div[data-waa-inc-params="' + idx + '"]').remove();
|
||||
if(parent.children().length == 0) {
|
||||
addNewParam(0);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(document).on('click', "#add_param", function(event) {
|
||||
event.preventDefault();
|
||||
addNewParam();
|
||||
});
|
||||
|
||||
jQuery(document).on('click','button[data-waa-action="remove_param"]', function(event) {
|
||||
event.preventDefault();
|
||||
var idx = event.currentTarget.getAttribute('data-waa-inc-params');
|
||||
removeParam(idx);
|
||||
return false;
|
||||
});
|
||||
|
||||
</script>
|
189
plugins/wide-angle-analytics/wide-angle-analytics.php
Normal file
189
plugins/wide-angle-analytics/wide-angle-analytics.php
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: Wide Angle Analytics
|
||||
Plugin URI: https://wordpress.org/plugins/wide-angle-analytics/
|
||||
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.0
|
||||
Requires at least: 5.2
|
||||
Requires PHP: 7.4
|
||||
License: GPL v2
|
||||
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
class WideAngleAnalytics {
|
||||
|
||||
const WAA_SEPARTOR = "|:";
|
||||
const WAA_CONF_SITE_ID = "waa_site_id";
|
||||
const WAA_CONF_TRACKER_DOMAIN = "waa_tracker_domain";
|
||||
const WAA_CONF_EXC_PATHS = "waa_exc_path";
|
||||
const WAA_CONF_INC_PARAMS = "waa_inc_params";
|
||||
const WAA_CONF_IGNORE_HASH = "waa_ignore_hash";
|
||||
const WAA_CONF_GENERATED_HEADER_SCRIPT = "waa_header_script";
|
||||
const WAA_CONF_GENERATED_FOOTER_SCRIPT = "waa_footer_script";
|
||||
|
||||
public function __construct() {
|
||||
$this->plugin = new stdClass;
|
||||
$this->plugin->name = 'wide-angle-analytics';
|
||||
$this->plugin->displayName = 'Wide Angle Analytics';
|
||||
$this->plugin->folder = plugin_dir_path( __FILE__ );
|
||||
include_once( $this->plugin->folder . '/types/WideAngleHelpers.php' );
|
||||
|
||||
$this->plugin->helpers = new WideAngleHelpers();
|
||||
$this->plugin->exclusionTypes = array(
|
||||
"start" => "Starts with",
|
||||
"end" => "Ends with",
|
||||
"regex" => "RegEx",
|
||||
);
|
||||
|
||||
add_action( 'admin_init', array( &$this, 'registerPluginSettings' ) );
|
||||
add_action( 'admin_menu', array( &$this, 'registerAdminMenu' ));
|
||||
add_action('wp_head', array( &$this, 'renderHeaderScript'));
|
||||
add_action('wp_footer', array( &$this, 'renderFooterScript'));
|
||||
}
|
||||
|
||||
/**
|
||||
* When script is configured and saved, function will render prefetch script directive.
|
||||
* Inteded to be used with 'wp_head' hook.
|
||||
*/
|
||||
function renderHeaderScript() {
|
||||
$this->renderSetting(self::WAA_CONF_GENERATED_HEADER_SCRIPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* When script is configured and saved, function will render Wide Angle Analytics script.
|
||||
* Inteded to be used with 'wp_footer' hook.
|
||||
*/
|
||||
function renderFooterScript() {
|
||||
$this->renderSetting(self::WAA_CONF_GENERATED_FOOTER_SCRIPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* When called, renders content of named setting.
|
||||
* Rendering is omitted if current view is: Admin, Feed, Robots or Trackback.
|
||||
*/
|
||||
function renderSetting($setting) {
|
||||
if (
|
||||
is_admin() ||
|
||||
is_feed() ||
|
||||
is_robots() ||
|
||||
is_trackback()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script = get_option($setting);
|
||||
if(trim($script) === "") {
|
||||
return;
|
||||
}
|
||||
echo wp_unslash($script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Wide Angle Analytics configuration menu to Admin "Settings" menu.
|
||||
*/
|
||||
function registerAdminMenu() {
|
||||
add_submenu_page(
|
||||
'options-general.php',
|
||||
$this->plugin->displayName,
|
||||
$this->plugin->displayName,
|
||||
'manage_options',
|
||||
$this->plugin->name,
|
||||
array( &$this, 'adminPanelHandler' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle configuration submission.
|
||||
*
|
||||
* When successful, the generated script will rendered and storedin plugin keyed setting.
|
||||
* This setting will be subsequently used when time comes to render it. The intermediate settings
|
||||
* are parsed and processed only during configuration change.
|
||||
*
|
||||
*/
|
||||
function adminPanelHandler() {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( __( 'Insufficient permissions. You are not allows to modify setting.', $this->plugin->displayName ) );
|
||||
}
|
||||
if ( isset( $_REQUEST['submit'] ) ) {
|
||||
if ( ! isset( $_REQUEST[ $this->plugin->name . '_nonce' ] ) ) {
|
||||
$this->errorMessage = __( 'Nonce field is missing. Settings NOT saved.',$this->plugin->name );
|
||||
} elseif ( ! wp_verify_nonce( $_REQUEST[ $this->plugin->name . '_nonce' ], $this->plugin->name ) ) {
|
||||
$this->errorMessage = __( 'Invalid nonce specified. Settings NOT saved.', $this->plugin->name );
|
||||
} else {
|
||||
$waaSiteId = $_REQUEST['waa_site_id'];
|
||||
$waaTrackerDomain = $this->plugin->helpers->normalizeTrackerDomain(trim($_REQUEST['waa_tracker_domain']));
|
||||
$waaIgnoreHash = $this->plugin->helpers->normalizeBoolean($_REQUEST['waa_ignore_hash']);
|
||||
$waaExclusionPaths = implode(self::WAA_SEPARTOR, $this->plugin->helpers->parseRequestExclusionPaths($_REQUEST));
|
||||
$waaIncParams = implode(self::WAA_SEPARTOR, $this->plugin->helpers->parseRequestIncludeParams($_REQUEST));
|
||||
|
||||
include_once( $this->plugin->folder . '/types/WideAngleConfig.php' );
|
||||
$config = new WideAngleConfig($waaSiteId, $waaTrackerDomain, $waaIgnoreHash, $waaExclusionPaths, $waaIncParams);
|
||||
|
||||
update_option(self::WAA_CONF_GENERATED_FOOTER_SCRIPT, $config->generateFooterScript());
|
||||
update_option(self::WAA_CONF_GENERATED_HEADER_SCRIPT, $config->generateHeaderScript());
|
||||
update_option(self::WAA_CONF_SITE_ID, $waaSiteId );
|
||||
update_option(self::WAA_CONF_TRACKER_DOMAIN, $waaTrackerDomain);
|
||||
update_option(self::WAA_CONF_IGNORE_HASH, $waaIgnoreHash );
|
||||
update_option(self::WAA_CONF_EXC_PATHS, $waaExclusionPaths );
|
||||
update_option(self::WAA_CONF_INC_PARAMS, $waaIncParams);
|
||||
}
|
||||
}
|
||||
$this->settings = array(
|
||||
self::WAA_CONF_SITE_ID => esc_html(get_option( self::WAA_CONF_SITE_ID)),
|
||||
self::WAA_CONF_EXC_PATHS => esc_html(get_option( self::WAA_CONF_EXC_PATHS)),
|
||||
self::WAA_CONF_INC_PARAMS => esc_html(get_option( self::WAA_CONF_INC_PARAMS)),
|
||||
self::WAA_CONF_TRACKER_DOMAIN => esc_html(get_option( self::WAA_CONF_TRACKER_DOMAIN)),
|
||||
self::WAA_CONF_IGNORE_HASH => esc_html(get_option( self::WAA_CONF_IGNORE_HASH)),
|
||||
self::WAA_CONF_GENERATED_HEADER_SCRIPT => esc_html(get_option( self::WAA_CONF_GENERATED_HEADER_SCRIPT )),
|
||||
self::WAA_CONF_GENERATED_FOOTER_SCRIPT => esc_html(get_option( self::WAA_CONF_GENERATED_FOOTER_SCRIPT )),
|
||||
);
|
||||
include_once( $this->plugin->folder . '/views/admin_settings.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates settings for Wide Angle Analytics plugin.
|
||||
*
|
||||
* Following settings are registered:
|
||||
* - waa_site_id
|
||||
* - waa_tracker_domain
|
||||
* - waa_exc_path
|
||||
* - waa_inc_params
|
||||
* - waa_ignore_hash
|
||||
* - waa_header_script
|
||||
* - waa_footer_script
|
||||
*/
|
||||
function registerPluginSettings() {
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_SITE_ID, array(
|
||||
'sanitize_callback' => 'trim',
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_EXC_PATHS, array(
|
||||
'sanitize_callback' => 'trim',
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_INC_PARAMS, array(
|
||||
'sanitize_callback' =>'trim',
|
||||
'default' => ''
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_TRACKER_DOMAIN, array(
|
||||
'sanitize_callback' => array(&$this->plugin->helpers, 'normalizeTrackerDomain'),
|
||||
'default' => 'https://stats.wideangle.co'
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_IGNORE_HASH, array(
|
||||
'sanitize_callback' => array(&$this->plugin->helpers, 'normalizeBoolean'),
|
||||
'default' => 'false'
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_GENERATED_HEADER_SCRIPT, array(
|
||||
'sanitize_callback' => 'trim',
|
||||
'default' => ''
|
||||
) );
|
||||
register_setting( $this->plugin->name, self::WAA_CONF_GENERATED_FOOTER_SCRIPT, array(
|
||||
'sanitize_callback' => 'trim',
|
||||
'default' => ''
|
||||
) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$waa = new WideAngleAnalytics(); // Plugin is initialized on contruction.
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue