updated plugin WP-Matomo Integration version 1.0.28

This commit is contained in:
KawaiiPunk 2023-06-05 11:21:32 +00:00 committed by Gitium
parent 579c0de01c
commit d9b3c97e40
8 changed files with 82 additions and 57 deletions

View File

@ -10,7 +10,7 @@ use WP_Piwik\Widget\Post;
*/ */
class WP_Piwik { class WP_Piwik {
private static $revisionId = 2022020701, $version = '1.0.27', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId; private static $revisionId = 2023052101, $version = '1.0.28', $blog_id, $pluginBasename = NULL, $logger, $settings, $request, $optionsPageId;
/** /**
* Constructor class to configure and register all WP-Piwik components * Constructor class to configure and register all WP-Piwik components
@ -1152,7 +1152,12 @@ class WP_Piwik {
'urls' => $isCurrent ? get_bloginfo ( 'url' ) : get_blog_details ( $blogId )->siteurl, 'urls' => $isCurrent ? get_bloginfo ( 'url' ) : get_blog_details ( $blogId )->siteurl,
'siteName' => urlencode( $isCurrent ? get_bloginfo ( 'name' ) : get_blog_details ( $blogId )->blogname ) 'siteName' => urlencode( $isCurrent ? get_bloginfo ( 'name' ) : get_blog_details ( $blogId )->blogname )
) ); ) );
$result = (int) $this->request ( $id ); $result = $this->request ( $id );
if ( is_array( $result ) && isset( $result['value'] ) ) {
$result = (int) $result['value'];
} else {
$result = (int) $result;
}
self::$logger->log ( 'Create Matomo ID: WordPress site ' . ($isCurrent ? get_bloginfo ( 'url' ) : get_blog_details ( $blogId )->siteurl) . ' = Matomo ID ' . $result ); self::$logger->log ( 'Create Matomo ID: WordPress site ' . ($isCurrent ? get_bloginfo ( 'url' ) : get_blog_details ( $blogId )->siteurl) . ' = Matomo ID ' . $result );
if (empty ( $result )) if (empty ( $result ))
return null; return null;
@ -1319,7 +1324,7 @@ class WP_Piwik {
* Get option value, choose method depending on network mode * Get option value, choose method depending on network mode
* *
* @param string $option option key * @param string $option option key
* @return string option value * @return string|array option value
*/ */
private function getWordPressOption($option, $default = null) { private function getWordPressOption($option, $default = null) {
return ($this->isNetworkMode () ? get_site_option ( $option, $default ) : get_option ( $option, $default )); return ($this->isNetworkMode () ? get_site_option ( $option, $default ) : get_option ( $option, $default ));

View File

@ -260,7 +260,13 @@ class Settings extends \WP_Piwik\Admin {
$this->showInput ( 'add_download_extensions', __ ( 'Add new file types for download tracking', 'wp-piwik' ), __ ( 'Add file extensions for download tracking, divided by a vertical bar (&#124;).', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="https://developer.piwik.org/guides/tracking-javascript-guide#file-extensions-for-tracking-downloads" target="_BLANK">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup ); $this->showInput ( 'add_download_extensions', __ ( 'Add new file types for download tracking', 'wp-piwik' ), __ ( 'Add file extensions for download tracking, divided by a vertical bar (&#124;).', 'wp-piwik' ) . ' ' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="https://developer.piwik.org/guides/tracking-javascript-guide#file-extensions-for-tracking-downloads" target="_BLANK">', '</a>' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
$this->showCheckbox ( 'disable_cookies', __ ( 'Disable cookies', 'wp-piwik' ), __ ( 'Disable all tracking cookies for a visitor.', 'wp-piwik' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup ); $this->showSelect ( 'require_consent', __ ( 'Tracking or cookie consent', 'wp-piwik' ), array (
'disabled' => __ ( 'Disabled', 'wp-piwik' ),
'consent' => __ ( 'Require consent', 'wp-piwik' ),
'cookieconsent' => __ ( 'Require cookie consent', 'wp-piwik' )
), __ ( 'Enable support for consent managers.' ) . ' ' . sprintf ( __ ( 'See %sMatomo documentation%s.', 'wp-piwik' ), '<a href="https://developer.matomo.org/guides/tracking-consent" target="_BLANK">', '</a>' ), '', $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
$this->showCheckbox ( 'disable_cookies', __ ( 'Disable cookies', 'wp-piwik' ), __ ( 'Disable all tracking cookies for a visitor.', 'wp-piwik' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup );
$this->showCheckbox ( 'limit_cookies', __ ( 'Limit cookie lifetime', 'wp-piwik' ), __ ( 'You can limit the cookie lifetime to avoid tracking your users over a longer period as necessary.', 'wp-piwik' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup, true, 'jQuery(\'tr.wp-piwik-cookielifetime-option\').toggleClass(\'wp-piwik-hidden\');' ); $this->showCheckbox ( 'limit_cookies', __ ( 'Limit cookie lifetime', 'wp-piwik' ), __ ( 'You can limit the cookie lifetime to avoid tracking your users over a longer period as necessary.', 'wp-piwik' ), $isNotGeneratedTracking, $fullGeneratedTrackingGroup, true, 'jQuery(\'tr.wp-piwik-cookielifetime-option\').toggleClass(\'wp-piwik-hidden\');' );
@ -526,9 +532,6 @@ class Settings extends \WP_Piwik\Admin {
<p> <p>
<?php _e('If you like WP-Matomo, you can support its development by a donation:', 'wp-piwik'); ?> <?php _e('If you like WP-Matomo, you can support its development by a donation:', 'wp-piwik'); ?>
</p> </p>
<div>
<script id='fb0ahsp'>(function(i){var f,s=document.getElementById(i);f=document.createElement('iframe');f.src='//button.flattr.com/view/?fid=mkdp7z&url=https%3A%2F%2Fwww.braekling.de%2Fwp-piwik-wpmu-piwik-wordpress';f.title='Flattr';f.height=62;f.width=55;f.style.borderWidth=0;s.parentNode.insertBefore(f,s);})('fb0ahsp');</script>
</div>
<div> <div>
Paypal Paypal
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
@ -545,9 +548,6 @@ class Settings extends \WP_Piwik\Admin {
<div> <div>
<a href="http://www.amazon.de/gp/registry/wishlist/111VUJT4HP1RA?reveal=unpurchased&amp;filter=all&amp;sort=priority&amp;layout=standard&amp;x=12&amp;y=14"><?php _e('My Amazon.de wishlist', 'wp-piwik'); ?></a> <a href="http://www.amazon.de/gp/registry/wishlist/111VUJT4HP1RA?reveal=unpurchased&amp;filter=all&amp;sort=priority&amp;layout=standard&amp;x=12&amp;y=14"><?php _e('My Amazon.de wishlist', 'wp-piwik'); ?></a>
</div> </div>
<div>
<?php _e('Please don\'t forget to vote the compatibility at the','wp-piwik'); ?> <a target="_BLANK" href="http://wordpress.org/extend/plugins/wp-piwik/">WordPress.org Plugin Directory</a>.
</div>
</div><?php </div><?php
} }

View File

@ -19,7 +19,6 @@
return; return;
} }
echo '<p>'.__('Currently shown stats:').' <a href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a>.'.' <a href="?page=wp-piwik_stats&overview=1">Show site overview</a>.</p>'; echo '<p>'.__('Currently shown stats:').' <a href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a>.'.' <a href="?page=wp-piwik_stats&overview=1">Show site overview</a>.</p>';
echo '</form>'."\n";
} }
echo '<form action="admin-post.php" method="post"><input type="hidden" name="action" value="save_wp-piwik_stats_general" /><div id="dashboard-widgets" class="metabox-holder columns-'.$screen_layout_columns.(2 <= $screen_layout_columns?' has-right-sidebar':'').'">'; echo '<form action="admin-post.php" method="post"><input type="hidden" name="action" value="save_wp-piwik_stats_general" /><div id="dashboard-widgets" class="metabox-holder columns-'.$screen_layout_columns.(2 <= $screen_layout_columns?' has-right-sidebar':'').'">';
wp_nonce_field('wp-piwik_stats-general'); wp_nonce_field('wp-piwik_stats-general');

View File

@ -75,6 +75,7 @@ class Settings {
'set_download_extensions' => '', 'set_download_extensions' => '',
'set_link_classes' => '', 'set_link_classes' => '',
'set_download_classes' => '', 'set_download_classes' => '',
'require_consent' => 'disabled',
'disable_cookies' => false, 'disable_cookies' => false,
'limit_cookies' => false, 'limit_cookies' => false,
'limit_cookies_visitor' => 34186669, // Piwik default 13 months 'limit_cookies_visitor' => 34186669, // Piwik default 13 months
@ -147,6 +148,7 @@ class Settings {
return; return;
} }
self::$wpPiwik->log ( 'Save settings' ); self::$wpPiwik->log ( 'Save settings' );
$this->globalSettings['plugin_display_name'] = htmlspecialchars($this->globalSettings['plugin_display_name'], ENT_QUOTES, 'utf-8');
foreach ( $this->globalSettings as $key => $value ) { foreach ( $this->globalSettings as $key => $value ) {
if ( $this->checkNetworkActivation() ) if ( $this->checkNetworkActivation() )
update_site_option ( 'wp-piwik_global-' . $key, $value ); update_site_option ( 'wp-piwik_global-' . $key, $value );

View File

@ -82,7 +82,7 @@ class TrackingCode {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', '" . ($settings->getGlobalOption ( 'set_download_classes' )) . "']);\n_paq.push(['trackPageView']);", $code ); $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setDownloadClasses', '" . ($settings->getGlobalOption ( 'set_download_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'set_link_classes' )) if ($settings->getGlobalOption ( 'set_link_classes' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', '" . ($settings->getGlobalOption ( 'set_link_classes' )) . "']);\n_paq.push(['trackPageView']);", $code ); $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setLinkClasses', '" . ($settings->getGlobalOption ( 'set_link_classes' )) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'limit_cookies' )) if ($settings->getGlobalOption ( 'limit_cookies' ))
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setVisitorCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_visitor' ) . "']);\n_paq.push(['setSessionCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_session' ) . "']);\n_paq.push(['setReferralCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_referral' ) . "']);\n_paq.push(['trackPageView']);", $code ); $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['setVisitorCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_visitor' ) . "']);\n_paq.push(['setSessionCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_session' ) . "']);\n_paq.push(['setReferralCookieTimeout', '" . $settings->getGlobalOption ( 'limit_cookies_referral' ) . "']);\n_paq.push(['trackPageView']);", $code );
if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled') if ($settings->getGlobalOption ( 'force_protocol' ) != 'disabled')
$code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code ); $code = str_replace ( '"//', '"' . $settings->getGlobalOption ( 'force_protocol' ) . '://', $code );
@ -92,6 +92,11 @@ class TrackingCode {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code ); $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
if ((int) $settings->getGlobalOption ( 'track_heartbeat' ) > 0) if ((int) $settings->getGlobalOption ( 'track_heartbeat' ) > 0)
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', ".(int) $settings->getGlobalOption ( 'track_heartbeat' )."]);", $code ); $code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['enableHeartBeatTimer', ".(int) $settings->getGlobalOption ( 'track_heartbeat' )."]);", $code );
if ($settings->getGlobalOption ( 'require_consent' ) == 'consent') {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['requireConsent']);\n_paq.push(['trackPageView']);", $code );
} elseif ($settings->getGlobalOption ( 'require_consent' ) == 'cookieconsent') {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['requireCookieConsent']);\n_paq.push(['trackPageView']);", $code );
}
$noScript = array (); $noScript = array ();
preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript ); preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript );
@ -118,9 +123,9 @@ class TrackingCode {
} }
private function applySearchChanges() { private function applySearchChanges() {
global $wp_query;
self::$wpPiwik->log ( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) ); self::$wpPiwik->log ( 'Apply search tracking changes. Blog ID: ' . get_current_blog_id () . ' Site ID: ' . self::$wpPiwik->getOption ( 'site_id' ) );
$objSearch = new \WP_Query ( "s=" . get_search_query () . '&showposts=-1' ); $intResultCount = $wp_query->found_posts;
$intResultCount = $objSearch->post_count;
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode ); $this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
} }

View File

@ -1,45 +1,51 @@
<?php <?php
namespace WP_Piwik\Widget; namespace WP_Piwik\Widget;
class Ecommerce extends \WP_Piwik\Widget { class Ecommerce extends \WP_Piwik\Widget
{
public $className = __CLASS__;
protected function configure($prefix = '', $params = array()) { public $className = __CLASS__;
$timeSettings = $this->getTimeSettings();
$this->title = $prefix.__('E-Commerce', 'wp-piwik'); protected function configure($prefix = '', $params = array())
$this->method = 'Goals.get'; {
$this->parameter = array( $timeSettings = $this->getTimeSettings();
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId), $this->title = $prefix . __('E-Commerce', 'wp-piwik');
'period' => $timeSettings['period'], $this->method = 'Goals.get';
'date' => $timeSettings['date'] $this->parameter = array(
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
'period' => $timeSettings['period'],
'date' => $timeSettings['date']
);
}
public function show()
{
$response = self::$wpPiwik->request($this->apiID[$this->method]);
if (!empty($response['result']) && $response['result'] = 'error')
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
else {
$tableHead = null;
$revenue = is_float($this->value($response, 'revenue')) ? number_format($this->value($response, 'revenue'), 2) : "";
$revenue_new = is_float($this->value($response, 'revenue_new_visit')) ? number_format($this->value($response, 'revenue_new_visit'), 2) : "";
$revenue_return = is_float($this->value($response, 'revenue_returning_visit')) ? number_format($this->value($response, 'revenue_returning_visit'), 2) : "";
$tableBody = array(
array(__('Conversions', 'wp-piwik') . ':', $this->value($response, 'nb_conversions')),
array(__('Visits converted', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted')),
array(__('Revenue', 'wp-piwik') . ':', $revenue),
array(__('Conversion rate', 'wp-piwik') . ':', $this->value($response, 'conversion_rate')),
array(__('Conversions (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_new_visit')),
array(__('Visits converted (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_new_visit')),
array(__('Revenue (new visitor)', 'wp-piwik') . ':', $revenue_new),
array(__('Conversion rate (new visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_new_visit')),
array(__('Conversions (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_returning_visit')),
array(__('Visits converted (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_returning_visit')),
array(__('Revenue (returning visitor)', 'wp-piwik') . ':', $revenue_return),
array(__('Conversion rate (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_returning_visit')),
); );
} $tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '">Piwik</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
$this->table($tableHead, $tableBody, $tableFoot);
public function show() { }
$response = self::$wpPiwik->request($this->apiID[$this->method]); }
if (!empty($response['result']) && $response['result'] ='error')
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8'); }
else {
$tableHead = null;
$tableBody = array(
array(__('Conversions', 'wp-piwik').':', $this->value($response, 'nb_conversions')),
array(__('Visits converted', 'wp-piwik').':', $this->value($response, 'nb_visits_converted')),
array(__('Revenue', 'wp-piwik').':', number_format($this->value($response, 'revenue'),2)),
array(__('Conversion rate', 'wp-piwik').':', $this->value($response, 'conversion_rate')),
array(__('Conversions (new visitor)', 'wp-piwik').':', $this->value($response, 'nb_conversions_new_visit')),
array(__('Visits converted (new visitor)', 'wp-piwik').':', $this->value($response, 'nb_visits_converted_new_visit')),
array(__('Revenue (new visitor)', 'wp-piwik').':', number_format($this->value($response, 'revenue_new_visit'),2)),
array(__('Conversion rate (new visitor)', 'wp-piwik').':', $this->value($response, 'conversion_rate_new_visit')),
array(__('Conversions (returning visitor)', 'wp-piwik').':', $this->value($response, 'nb_conversions_returning_visit')),
array(__('Visits converted (returning visitor)', 'wp-piwik').':', $this->value($response, 'nb_visits_converted_returning_visit')),
array(__('Revenue (returning visitor)', 'wp-piwik').':', number_format($this->value($response, 'revenue_returning_visit'),2)),
array(__('Conversion rate (returning visitor)', 'wp-piwik').':', $this->value($response, 'conversion_rate_returning_visit')),
);
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut')?array(__('Shortcut', 'wp-piwik').':', '<a href="'.self::$settings->getGlobalOption('piwik_url').'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik_stats">WP-Piwik</a>':'')):null);
$this->table($tableHead, $tableBody, $tableFoot);
}
}
}

View File

@ -2,8 +2,8 @@
Contributors: Braekling Contributors: Braekling
Requires at least: 5.0 Requires at least: 5.0
Tested up to: 5.9 Tested up to: 6.2
Stable tag: 1.0.27 Stable tag: 1.0.28
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
Tags: matomo, tracking, statistics, stats, analytics Tags: matomo, tracking, statistics, stats, analytics
@ -143,6 +143,14 @@ Add WP-Matomo to your /wp-content/plugins folder and enable it as [Network Plugi
== Changelog == == Changelog ==
= 1.0.28 =
* Encode plugin display name
* Option to set requireConsent or requireCookieConsent
* Avoid notice on empty ecommerce data
* Improve search tracking performance (thanks to theodejager, [details](https://github.com/braekling/WP-Matomo/pull/111))
* Fix multisite sub-site tracking (thanks to ulkoalex, [details](https://github.com/braekling/WP-Matomo/issues/107))
* Remove excess form closing tag (thanks to ulkoalex, [details](https://github.com/braekling/WP-Matomo/pull/113))
= 1.0.27 = = 1.0.27 =
* Fix a CSRF vulnerability * Fix a CSRF vulnerability
* Fix JavaScript typos on settings page which broke some interface functionality * Fix JavaScript typos on settings page which broke some interface functionality

View File

@ -6,7 +6,7 @@ Plugin URI: http://wordpress.org/extend/plugins/wp-piwik/
Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog. Description: Adds Matomo statistics to your WordPress dashboard and is also able to add the Matomo Tracking Code to your blog.
Version: 1.0.27 Version: 1.0.28
Author: Andr&eacute; Br&auml;kling Author: Andr&eacute; Br&auml;kling
Author URI: https://www.braekling.de Author URI: https://www.braekling.de
Text Domain: wp-piwik Text Domain: wp-piwik