PluginProbe
Include Matomo Tracking, by Jonas Hellmann / 1.2
Include Matomo Tracking, by Jonas Hellmann v1.2
trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2
← All changes | include-matomo.php +118 -129 1.51.2 View file →
@@ -1,129 +1,118 @@
1 -<?php
2 -/*
3 -Plugin Name: Include Matomo Tracking, by Jonas Hellmann
4 -Plugin URI: https://github.com/jonashellmann/include-matomo/
5 -Description: This plugin includes Matomo into your Wordpress site
6 -Version: 1.5
7 -Author: Jonas Hellmann
8 -Author URI: https://jonas-hellmann.de/en/
9 -License: GPL3
10 -*/
11 -
12 -if( get_option('matomo_url') !== '' && get_option('matomo_site_id') !== '0' ) {
13 - add_action( 'wp_footer', 'include_matomo_script' );
14 -}
15 -
16 -function include_matomo_script() {
17 - echo "<!-- Include Matomo -->\n";
18 - echo "<script type='text/javascript'>\n";
19 - echo " var _paq = _paq || [];\n";
20 - echo " _paq.push(['trackPageView']);\n";
21 - echo " _paq.push(['enableLinkTracking']);\n";
22 - echo " (function() {\n";
23 - echo " var u='//" . get_matomo_url() . "/';\n";
24 - echo " _paq.push(['setTrackerUrl', u+'piwik.php']);\n";
25 - echo " _paq.push(['setSiteId', '" . get_option('matomo_site_id') . "']);\n";
26 - if (get_option('matomo_disable_cookies', 'n') == 'y') {
27 - echo " _paq.push([‘disableCookies’]);\n";
28 - }
29 - echo " var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];\n";
30 - echo " g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);\n";
31 - echo " })();\n";
32 - echo "</script>\n";
33 - echo "<!-- End Matomo Code-->\n";
34 -}
35 -
36 -function get_matomo_url() {
37 - $matomo_url = get_option('matomo_url');
38 - if( substr_compare( $matomo_url, '/', -1, 1 ) == 0 ) {
39 - $matomo_url = substr( $matomo_url, 0, -1 );
40 - }
41 - if( substr_compare( $matomo_url, 'https://', 0, 8 ) == 0 ) {
42 - $matomo_url = substr( $matomo_url, 8 );
43 - }
44 - if( substr_compare( $matomo_url, 'http://', 0, 7 ) == 0 ) {
45 - $matomo_url = substr( $matomo_url, 7 );
46 - }
47 - return $matomo_url;
48 -}
49 -
50 -// TODO: Only include if this should be used
51 -add_filter( 'the_permalink_rss', 'add_matomo_campaign_to_rss' );
52 -
53 -function add_matomo_campaign_to_rss($guid) {
54 - global $post;
55 - $get_vars = array(
56 - 'pk_campaign=' . urlencode( get_option('matomo_rss_campaign') ),
57 - 'pk_source=' . urlencode( get_option('matomo_rss_source') )
58 - );
59 - return $guid . '?' . implode( '&', $get_vars );
60 -}
61 -
62 -
63 -add_action('admin_menu', 'include_matomo_menu');
64 -
65 -function include_matomo_menu() {
66 - add_submenu_page('options-general.php', 'Include Matomo - Settings', 'Include Matomo', 'administrator', 'include-matomo-settings', 'include_matomo_settings_page');
67 -}
68 -
69 -add_action( 'admin_init', 'my_plugin_settings' );
70 -
71 -function my_plugin_settings() {
72 - register_setting( 'include-matomo-settings-group', 'matomo_url' );
73 - register_setting( 'include-matomo-settings-group', 'matomo_site_id' );
74 - register_setting( 'include-matomo-settings-group', 'matomo_rss_campaign' );
75 - register_setting( 'include-matomo-settings-group', 'matomo_rss_source' );
76 - register_setting( 'include-matomo-settings-group', 'matomo_disable_cookies' );
77 -}
78 -
79 -function include_matomo_settings_page() { ?>
80 - <div class="wrap">
81 - <h2>Matomo Settings</h2>
82 -
83 - <form method="post" action="options.php">
84 - <?php settings_fields( 'include-matomo-settings-group' ); ?>
85 - <?php do_settings_sections( 'include-matomo-settings-group' ); ?>
86 - <table class="form-table">
87 - <tr valign="top">
88 - <th scope="row">Matomo URL</th>
89 - <td>
90 - <input type="text" name="matomo_url" value="<?php echo esc_attr( get_option('matomo_url') ); ?>" />
91 - </td>
92 - </tr>
93 -
94 - <tr valign="top">
95 - <th scope="row">Matomo Page ID</th>
96 - <td>
97 - <input type="number" name="matomo_site_id" value="<?php echo esc_attr( get_option('matomo_site_id') ); ?>" />
98 - </td>
99 - </tr>
100 -
101 - <tr valign="top">
102 - <th scope="row">Matomo RSS Campaign</th>
103 - <td>
104 - <input type="text" name="matomo_rss_campaign" value="<?php echo esc_attr( get_option('matomo_rss_campaign') ); ?>" />
105 - </td>
106 - </tr>
107 -
108 - <tr valign="top">
109 - <th scope="row">Matomo RSS Source</th>
110 - <td>
111 - <input type="text" name="matomo_rss_source" value="<?php echo esc_attr( get_option('matomo_rss_source') ); ?>" />
112 - </td>
113 - </tr>
114 -
115 - <tr valign="top">
116 - <th scope="row">Matomo Disable Cookies? (y/n)</th>
117 - <td>
118 - <input type="text" name="matomo_disable_cookies" value="<?php echo esc_attr( get_option('matomo_disable_cookies', 'n') ); ?>" />
119 - </td>
120 - </tr>
121 - </table>
122 -
123 - <?php submit_button(); ?>
124 -
125 - </form>
126 - </div> <?php
127 -}
128 -
129 -?>
1 +<?php
2 +/*
3 +Plugin Name: Include Matomo
4 +Plugin URI: https://github.com/jonashellmann/include-matomo/
5 +Description: This plugin includes Matomo into your Wordpress site
6 +Version: 1.2
7 +Author: Jonas Hellmann
8 +Author URI: https://jonas-hellmann.de/en/
9 +License: GPL3
10 +*/
11 +
12 +if( get_option('matomo_url') !== '' && get_option('matomo_site_id') !== '0' ) {
13 + add_action( 'wp_footer', 'include_matomo_script' );
14 +}
15 +
16 +function include_matomo_script() {
17 + echo "<!-- Include Matomo -->\n";
18 + echo "<script type='text/javascript'>\n";
19 + echo " var _paq = _paq || [];\n";
20 + echo " _paq.push(['trackPageView']);\n";
21 + echo " _paq.push(['enableLinkTracking']);\n";
22 + echo " (function() {\n";
23 + echo " var u='//" . get_matomo_url() . "/';\n";
24 + echo " _paq.push(['setTrackerUrl', u+'piwik.php']);\n";
25 + echo " _paq.push(['setSiteId', '" . get_option('matomo_site_id') . "']);\n";
26 + echo " var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];\n";
27 + echo " g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);\n";
28 + echo " })();\n";
29 + echo "</script>\n";
30 + echo "<!-- End Matomo Code-->\n";
31 +}
32 +
33 +function get_matomo_url() {
34 + $matomo_url = get_option('matomo_url');
35 + if( substr_compare( $matomo_url, '/', -1, 1 ) == 0 ) {
36 + $matomo_url = substr( $matomo_url, 0, -1 );
37 + }
38 + if( substr_compare( $matomo_url, 'https://', 0, 8 ) == 0 ) {
39 + $matomo_url = substr( $matomo_url, 8 );
40 + }
41 + if( substr_compare( $matomo_url, 'http://', 0, 7 ) == 0 ) {
42 + $matomo_url = substr( $matomo_url, 7 );
43 + }
44 + return $matomo_url;
45 +}
46 +
47 +// TODO: Only include if this should be used
48 +add_filter( 'the_permalink_rss', 'add_matomo_campaign_to_rss' );
49 +
50 +function add_matomo_campaign_to_rss($guid) {
51 + global $post;
52 + $get_vars = array(
53 + 'pk_campaign' . urlencode( get_option('matomo_rss_campaign') ),
54 + 'pk_source' . urlencode( get_option('matomo_rss_source') )
55 + );
56 + return $guid . '?' . implode( '&', $get_vars );
57 +}
58 +
59 +
60 +add_action('admin_menu', 'include_matomo_menu');
61 +
62 +function include_matomo_menu() {
63 + add_submenu_page('options-general.php', 'Include Matomo - Settings', 'Include Matomo', 'administrator', 'include-matomo-settings', 'include_matomo_settings_page');
64 +}
65 +
66 +add_action( 'admin_init', 'my_plugin_settings' );
67 +
68 +function my_plugin_settings() {
69 + register_setting( 'include-matomo-settings-group', 'matomo_url' );
70 + register_setting( 'include-matomo-settings-group', 'matomo_site_id' );
71 + register_setting( 'include-matomo-settings-group', 'matomo_rss_campaign' );
72 + register_setting( 'include-matomo-settings-group', 'matomo_rss_source' );
73 +}
74 +
75 +function include_matomo_settings_page() { ?>
76 + <div class="wrap">
77 + <h2>Matomo Settings</h2>
78 +
79 + <form method="post" action="options.php">
80 + <?php settings_fields( 'include-matomo-settings-group' ); ?>
81 + <?php do_settings_sections( 'include-matomo-settings-group' ); ?>
82 + <table class="form-table">
83 + <tr valign="top">
84 + <th scope="row">Matomo URL</th>
85 + <td>
86 + <input type="text" name="matomo_url" value="<?php echo esc_attr( get_option('matomo_url') ); ?>" />
87 + </td>
88 + </tr>
89 +
90 + <tr valign="top">
91 + <th scope="row">Matomo Page ID</th>
92 + <td>
93 + <input type="number" name="matomo_site_id" value="<?php echo esc_attr( get_option('matomo_site_id') ); ?>" />
94 + </td>
95 + </tr>
96 +
97 + <tr valign="top">
98 + <th scope="row">Matomo RSS Campaign</th>
99 + <td>
100 + <input type="text" name="matomo_rss_campaign" value="<?php echo esc_attr( get_option('matomo_rss_campaign') ); ?>" />
101 + </td>
102 + </tr>
103 +
104 + <tr valign="top">
105 + <th scope="row">Matomo RSS Source</th>
106 + <td>
107 + <input type="text" name="matomo_rss_source" value="<?php echo esc_attr( get_option('matomo_rss_source') ); ?>" />
108 + </td>
109 + </tr>
110 + </table>
111 +
112 + <?php submit_button(); ?>
113 +
114 + </form>
115 + </div> <?php
116 +}
117 +
118 +?>