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