Skip to content

Commit

Permalink
### 1.1.0
Browse files Browse the repository at this point in the history
* Fixed: tracking script is now output with a line break at the end.
* Fixed: Validation improvements for Ackee Domain ID and consent cookie fields.
* Enhancements: PHPCS ignore is more explicit.
* Added: Respects Do Not Track by default with an option to override and always output the tracker.
* Added: A cookie setting to allow visitors to opt-in to Ackee.
* Added: An option to output the detailed view.
  • Loading branch information
BrookeDot committed Jul 4, 2020
1 parent 918634a commit 0dd604c
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 30 deletions.
106 changes: 90 additions & 16 deletions includes/class-admin-settings.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php // phpcs:ignore -- ignore class naming
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- We don't use core's class naming convention
/**
* Admin Settings
*
* This file registers and outputs the admin page dispalyed WP Admin.
*
* @package Soapberry
* @author Brooke.
* @copyright 2019 Brooke.
* @copyright 2019-2020 Brooke.
* @license GPL-3.0-or-later
* @link https://brooke.codes/projects/soapberry
*/
Expand Down Expand Up @@ -34,7 +34,7 @@ public function __construct() {
* Register the Soapberry settings page under Settings menu
* Adds the Ackee instance settings for use on script output
*
* @since 0.1.0
* @since 1.0.0
* @access public
* @link https://developer.wordpress.org/reference/functions/add_options_page/
* @return void
Expand All @@ -52,7 +52,7 @@ public function soapberry_settings_page() {
/**
* Saves the sanatized data into the soapberry_settings option
*
* @since 0.1.0
* @since 1.0.0
* @access public
* @link https://developer.wordpress.org/reference/functions/register_setting/
* @return void
Expand All @@ -73,7 +73,7 @@ public function soapberry_register_settings() {
/**
* Callback to sanatizes the user input before saving the option into the database.
*
* @since 0.1.0
* @since 1.0.0
* @access public
* @param array $settings The data array from POST object.
* @return array
Expand All @@ -82,28 +82,38 @@ public function soapberry_validate_settings( $settings ) {
if ( ! isset( $_POST['soapberry_settings_options_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['soapberry_settings_options_nonce'] ), 'soapberry_settings_save_nonce' ) ) { // phpcs:ignore
return;
}

$soapberry_settings = $settings;
$soapberry_settings['instance_url'] = esc_url_raw( $settings['instance_url'] );
$soapberry_settings['tracking_script'] = sanitize_text_field( $settings['tracking_script'] );
$soapberry_settings['domain_id'] = sanitize_text_field( $settings['domain_id'] );
$soapberry_settings['domain_id'] = sanitize_text_field( str_replace( ' ', '-', trim( $settings['domain_id'] ) ) );
$soapberry_settings['consent_cookie'] = sanitize_text_field( str_replace( ' ', '_', strtolower( trim( $settings['consent_cookie'] ) ) ) );

if ( isset( $settings['exclude_logged_in'] ) && 1 === $settings['exclude_logged_in'] ) {
$soapberry_settings['exclude_logged_in'] = 1;
}

if ( isset( $settings['ignore_do_not_track'] ) && 1 === $settings['ignore_do_not_track'] ) {
$soapberry_settings['ignore_do_not_track'] = 1;
}

if ( isset( $settings['detailed_enabled'] ) && 1 === $settings['detailed_enabled'] ) {
$soapberry_settings['detailed_enabled'] = 1;
}

return $soapberry_settings;
}

/**
* HTML markup for the Settings page display. used by soapberry_settings_page()
*
* @since 0.1.0
* @since 1.0.0
* @access public
*/
public function soapberry_settings_display() {
$soapberry_settings = get_option( 'soapberry_settings' );
$exclude_logged_in = ( isset( $soapberry_settings['exclude_logged_in'] ) ) ? 1 : 0;
$soapberry_settings = get_option( 'soapberry_settings' );
$exclude_logged_in = ( isset( $soapberry_settings['exclude_logged_in'] ) ) ? 1 : 0;
$ignore_do_not_track = ( isset( $soapberry_settings['ignore_do_not_track'] ) ) ? 1 : 0;
$detailed_enabled = ( isset( $soapberry_settings['detailed_enabled'] ) ) ? 1 : 0;
?>
<div class="wrap">
<h1><?php echo esc_html__( 'Soapberry Settings', 'soapberry' ); ?></h1>
Expand Down Expand Up @@ -132,9 +142,9 @@ public function soapberry_settings_display() {
esc_html__( 'The name of your', 'soapberry' ),
/* Link and anchor text*/
sprintf(
'<a href="%s">%s</a>',
esc_url( 'https://github.com/electerious/Ackee#tracker' ),
esc_html__( 'Ackee Tracker', 'soapberry' )
'<a href="%s" target="_blank">%s</a>',
esc_url( 'https://docs.ackee.electerious.com/#/docs/Options#tracker' ),
esc_html__( 'Ackee tracker', 'soapberry' )
),
/* Wrapping script name in code tags*/
sprintf(
Expand Down Expand Up @@ -162,18 +172,82 @@ public function soapberry_settings_display() {
</p>
</td>
</tr>
<tr>
<th scope="row"><label for="soapberry_ackee_consent_cookie"><?php esc_html_e( 'Consent Cookie Name', 'soapberry' ); ?></label></th>
<td>
<input name="soapberry_settings[consent_cookie]" type="text" id="soapberry_ackee_consent_cookie" value="<?php echo ( esc_attr( $soapberry_settings['consent_cookie'] ) ); ?>" placeholder="Consent Cookie Name" class="regular-text">
<p class="description" id="soapberry_ackee_consent_cookie-description">
<?php esc_html_e( 'If set Soapberry will require a cookie with this value to be set as true before outputing the Ackee tracker.', 'soapberry' ); ?>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php echo esc_html__( 'Exclude Logged In', 'soapberry' ); ?></th>
<td>
<label for="soapberry_exclude_logged_in">
<input name="soapberry_settings[exclude_logged_in]" type="checkbox" id="soapberry_exclude_logged_in" value="1" <?php checked( $exclude_logged_in, 1 ); ?> >
<?php esc_html_e( "If checked, the tracking code won't be output for logged in visits.", 'soapberry' ); ?>
<input name="soapberry_settings[exclude_logged_in]" type="checkbox" id="soapberry_exclude_logged_in" value="1" <?php checked( $exclude_logged_in, 1 ); ?> >
<?php esc_html_e( "If checked, the Ackee tracker won't be output for logged in visits.", 'soapberry' ); ?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php echo esc_html__( 'Ignore Do Not Track Preference', 'soapberry' ); ?></th>
<td>
<label for="soapberry_ignore_do_not_track">
<input name="soapberry_settings[ignore_do_not_track]" type="checkbox" id="soapberry_ignore_do_not_track" value="1" <?php checked( $ignore_do_not_track, 1 ); ?> >
<?php
printf(
/* translators: This adds a link to the information on Do Not Track as a link. */
esc_html__( '%1$s %2$s %3$s', 'soapberry' ),
esc_html__( 'The default behavior is to respect', 'soapberry' ),
/* Link and anchor text */
sprintf(
'<a href="%s">%s</a>',
esc_url( 'https://allaboutdnt.com/' ),
esc_html__( 'Do Not Track', 'soapberry' )
),
sprintf(
'%s<br>%s',
esc_html__( 'headers sent by the browser.', 'soapberry' ),
esc_html__( 'If checked, the Ackee tracker will still be output regrdless of the visitor\'s Do Not Track preference', 'soapberry' )
),
);
?>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php echo esc_html__( 'Use Detailed Stats', 'soapberry' ); ?></th>
<td>
<label for="soapberry_detailed_enabled">
<input name="soapberry_settings[detailed_enabled]" type="checkbox" id="soapberry_detailed_enabled" value="1" <?php checked( $detailed_enabled, 1 ); ?> >
<?php
printf(
/* translators: This adds a link to the information Personal Data. */
esc_html__( '%1$s %2$s', 'soapberry' ),
/* Wrap the word `detailed` in code since that's a paramater name */
sprintf(
'%s <code> %s</code> %s',
esc_html__( 'If checked, the Ackee tracker will include the', 'soapberry' ),
esc_html__( 'detailed' ),
esc_html__( 'parameter.', 'soapberry' ),
),
/* Output link to more information on the detailed view*/
sprintf(
'<br> %s <a href="%s">%s</a>%s',
esc_html__( 'As this data may be considered', 'soapberry' ),
esc_url( 'https://docs.ackee.electerious.com/#/docs/Anonymization#personal-data' ),
esc_html__( 'Personal Data', 'soapberry' ),
esc_html__( ', requiring a consent cookie is recommended.', 'soapberry' ),
),
);
?>
</label>
</td>
</tr>
</tbody>
</table>
<?php echo ( wp_nonce_field( 'soapberry_settings_save_nonce', 'soapberry_settings_options_nonce' ) ); // phpcs:ignore ?>
<?php echo ( wp_nonce_field( 'soapberry_settings_save_nonce', 'soapberry_settings_options_nonce' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Genrated field output by Core ?>
<?php submit_button(); ?>
</form>
<?php
Expand Down
21 changes: 17 additions & 4 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php // phpcs:ignore -- ignore class naming
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- We don't use core's class naming convention
/**
* Frontend Output
*
* This file is used to store functions that control the Ackee output on the front end of a site.
*
* @package Ackee_WP
* @package Soapberry
* @author Brooke.
* @copyright 2019 Brooke.
* @copyright 2019-2020 Brooke.
* @license GPL-3.0-or-later
* @link https://brooke.codes/projects/soapberry
*/
Expand Down Expand Up @@ -46,6 +46,17 @@ public function soapberry_maybe_show_script() {
return;
}

/* Don't display the script if the visitor has Do Not Track enabled (unless we have chosen to override it). */
if ( true !== (bool) $this->soapberry_get_options( 'ignore_do_not_track' ) && ( array_key_exists( 'HTTP_DNT', $_SERVER ) && ( 1 === (int) $_SERVER['HTTP_DNT'] ) ) ) {
return;
}

/* Don't display the script if a consent cookie is required but has not been set. */
$consent_cookie = $this->soapberry_get_options( 'consent_cookie' );
if ( ! empty( $consent_cookie ) && ! isset( $_COOKIE[ sanitize_text_field( $consent_cookie ) ] ) ) {
return;
}

/* All conditions are met to display the script to proceed with register and enqueue the script. */
add_filter( 'script_loader_tag', array( $this, 'soapberry_generate_script' ), 10, 3 );

Expand All @@ -68,7 +79,9 @@ public function soapberry_maybe_show_script() {
*/
public function soapberry_generate_script( $tag, $handle, $src ) {
if ( 'soapberry' === $handle ) {
$tag = '<script async src="' . $src . '" data-ackee-server="' . $this->soapberry_get_options( 'instance_url' ) . '" data-ackee-domain-id="' . $this->soapberry_get_options( 'domain_id' ) . '"></script>'; // phpcs:ignore -- False postive, not outputing script.
$detailed = ( true === (bool) $this->soapberry_get_options( 'detailed_enabled' ) ) ? " data-ackee-opts='{\"detailed\":true}'" : '';

$tag = '<script async src="' . $src . '" data-ackee-server="' . $this->soapberry_get_options( 'instance_url' ) . '" data-ackee-domain-id="' . $this->soapberry_get_options( 'domain_id' ) . '"' . $detailed . '></script>' . "\n\t"; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- False postive, not outputing script.
}
return $tag;
}
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@ If you're still not seeing the tracking code, make sure your settings have been

## Changelog

### 1.0
### 1.1.0
* Fixed: tracking script is now output with a line break at the end.+
* Fixed: Validation improvements for Ackee Domain ID and consent cookie fields.
* Enhancements: PHPCS ignore is more explicit.
* Added: Respects Do Not Track by default with an option to override and always output the tracker.
* Added: A cookie setting to allow visitors to opt-in to Ackee.
* Added: An option to output the `detailed` view.

### 1.0.0
* Inital release
16 changes: 12 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: brookedot
Tags: tracking, analytics, stats, ackee
Requires at least: 4.1
Tested up to: 5.3.2
Requires PHP: 5.6
Stable tag: 1.0.0
Tested up to: 5.4
Requires PHP: 7.2
Stable tag: 1.1.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -14,7 +14,7 @@ Gather data on site visits while respecting visitor privacy using Soapberry alon

Soapberry makes it possible to use an externally hosted [Ackee](https://ackee.electerious.com/) analytics instance with your WordPress site without editing any code. It provides a settings page in WP Admin to add the required JavaScript tracking elements to your site's footer.

To use this plugin, one must have access to an Ackee instance set up with a Domain ID and [CORS headers](https://github.com/electerious/Ackee/blob/master/docs/CORS%20headers.md) matching that of the WordPress domain.
To use this plugin, one must have access to an Ackee instance set up with a Domain ID and [CORS headers](https://docs.ackee.electerious.com/#/docs/CORS%20headers) matching that of the WordPress domain.

The upstream Ackee project describes the project as a:
> Self-hosted, Node.js based analytics tool for those who care about privacy. Ackee runs on your own server, analyses the traffic of your websites and provides useful statistics in a minimal interface.
Expand Down Expand Up @@ -55,5 +55,13 @@ If you're still not seeing the tracking code, make sure your settings have been

== Changelog ==

= 1.1.0 =
* Fixed: tracking script is now output with a line break at the end.
* Fixed: Validation improvements for Ackee Domain ID and consent cookie fields.
* Enhancements: PHPCS ignore is more explicit.
* Added: Respects Do Not Track by default with an option to override and always output the tracker.
* Added: A cookie setting to allow visitors to opt-in to Ackee.
* Added: An option to output the detailed view.

= 1.0 =
* Inital release
9 changes: 4 additions & 5 deletions soapberry.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?php // phpcs:ignore -- ignore class naming
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- We don't use core's class naming convention
/**
* Plugin Name
*
* @package Soapberry
* @author Brooke.
* @copyright 2020 Brooke.
* @copyright 2019-2020 Brooke.
* @license GPL-3.0-or-later
*
* @wordpress-plugin
* Plugin Name: Soapberry
* Plugin URI: https://brooke.codes/projects/soabperry
* Description: Collect data on your visitors while respecting their privacy using Soapberry with a self-hosted Ackee install.
* Version: 1.0.0
* Version: 1.1.0
* Requires at least: 4.1
* Requires PHP: 5.6
* Requires PHP: 7.2
* Author: Brooke.
* Author URI: https://broo.ke
* Text Domain: soapberry
* Domain Path: /languages
* License: GPL v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
Expand Down

0 comments on commit 0dd604c

Please sign in to comment.