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 {
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
@ -1152,7 +1152,12 @@ class WP_Piwik {
'urls' => $isCurrent ? get_bloginfo ( 'url' ) : get_blog_details ( $blogId )->siteurl,
'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 );
if (empty ( $result ))
return null;
@ -1319,7 +1324,7 @@ class WP_Piwik {
* Get option value, choose method depending on network mode
*
* @param string $option option key
* @return string option value
* @return string|array option value
*/
private function getWordPressOption($option, $default = null) {
return ($this->isNetworkMode () ? get_site_option ( $option, $default ) : get_option ( $option, $default ));

View File

@ -260,6 +260,12 @@ 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->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\');' );
@ -526,9 +532,6 @@ class Settings extends \WP_Piwik\Admin {
<p>
<?php _e('If you like WP-Matomo, you can support its development by a donation:', 'wp-piwik'); ?>
</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>
Paypal
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
@ -545,9 +548,6 @@ class Settings extends \WP_Piwik\Admin {
<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>
</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
}

View File

@ -19,7 +19,6 @@
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 '</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':'').'">';
wp_nonce_field('wp-piwik_stats-general');

View File

@ -75,6 +75,7 @@ class Settings {
'set_download_extensions' => '',
'set_link_classes' => '',
'set_download_classes' => '',
'require_consent' => 'disabled',
'disable_cookies' => false,
'limit_cookies' => false,
'limit_cookies_visitor' => 34186669, // Piwik default 13 months
@ -147,6 +148,7 @@ class Settings {
return;
}
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 ) {
if ( $this->checkNetworkActivation() )
update_site_option ( 'wp-piwik_global-' . $key, $value );

View File

@ -92,6 +92,11 @@ class TrackingCode {
$code = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackPageView']);\n_paq.push(['trackVisibleContentImpressions']);", $code );
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 );
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 ();
preg_match ( '/<noscript>(.*)<\/noscript>/', $code, $noScript );
@ -118,9 +123,9 @@ class TrackingCode {
}
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' ) );
$objSearch = new \WP_Query ( "s=" . get_search_query () . '&showposts=-1' );
$intResultCount = $objSearch->post_count;
$intResultCount = $wp_query->found_posts;
$this->trackingCode = str_replace ( "_paq.push(['trackPageView']);", "_paq.push(['trackSiteSearch','" . get_search_query () . "', false, " . $intResultCount . "]);\n_paq.push(['trackPageView']);", $this->trackingCode );
}

View File

@ -2,11 +2,13 @@
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()) {
protected function configure($prefix = '', $params = array())
{
$timeSettings = $this->getTimeSettings();
$this->title = $prefix . __('E-Commerce', 'wp-piwik');
$this->method = 'Goals.get';
@ -17,24 +19,28 @@
);
}
public function show() {
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').':', number_format($this->value($response, 'revenue'),2)),
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').':', number_format($this->value($response, 'revenue_new_visit'),2)),
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').':', number_format($this->value($response, 'revenue_returning_visit'),2)),
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);

View File

@ -2,8 +2,8 @@
Contributors: Braekling
Requires at least: 5.0
Tested up to: 5.9
Stable tag: 1.0.27
Tested up to: 6.2
Stable tag: 1.0.28
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
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 ==
= 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 =
* Fix a CSRF vulnerability
* 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.
Version: 1.0.27
Version: 1.0.28
Author: Andr&eacute; Br&auml;kling
Author URI: https://www.braekling.de
Text Domain: wp-piwik