How to use Piwik with WordPress
This article describes how to integrate WordPress with the open-source Piwik analytics platform.
Using Piwik with WordPress
Piwik gathers detailed statistics about visitor traffic to your site. You can integrate Piwik with WordPress using either of the following methods:
- Installing and configuring a WordPress plugin.
- Editing the WordPress theme directly.
The following sections describe how to do both of these methods.
Before you can use Piwik with WordPress, you must first install the Piwik application files. There are two ways to do this:
- If your hosting account includes Softaculous, you can use it to install Piwik.
- If your hosting account does not include Softaculous, or if you want to install the newest version, you can install Piwik manually.
Method #1: Use a WordPress plugin
There are several plugins available for WordPress that provide Piwik integration, but Piwik's own site recommends WP-Piwik. This section describes how to install and configure this plugin.
Installing WP-Piwik
To install the WP-Piwik plugin on your WordPress site, follow these steps:
- Log in to your WordPress site as the administrator.
- In the left-hand pane, click Plugins.
- Click Add New.
- In the Search Plugins text box, type wp-piwik, and then press Enter.
- Locate WP-Piwik, and then click Install Now.
- After WordPress finishes installing the plugin, click Activate Plugin.
Configuring WP-Piwik
After you install the WP-Piwik plugin, you must configure it to work with your Piwik installation. To do this, follow these steps:
- Log in to your WordPress site as the administrator.
- In the left-hand pane, click Settings, and then click WP-Piwik. The WP-Piwik Settings page appears.
- On the Connect to Piwik tab, in the Piwik Mode list box, select Self-hosted (PHP API).
- In the Piwik path text box, type the directory where you installed Piwik (for example, /home/username/public_html/piwik, where username represents your account username).
- In the Auth token text box, type your Piwik authentication token.
To obtain your Piwik authentication token, follow these steps:
- Log in to Piwik.
- On the top right of the page, click your administrator username.
- On the left menu bar, under Platform, click API.
- Under User authentication, copy the long alphanumeric string. This is your Piwik authentication token. (Do not copy the &token_auth= portion.)
- Confirm the Auto config check box is selected.
- Click Save Changes. You should receive a WP-Piwik is successfully connected to Piwik message. If you do not, check the values you provided in steps 3 to 6, and then try again.
- Click the Enable Tracking tab.
- In the Add tracking code list box, select Default tracking.
- Click Save Changes.
- To view Piwik statistics for your site, in the left-hand pane, click Dashboard, and then click WP-Piwik. The Piwik Statistics page appears with visitor statistics, site search statistics, and more.
Method #2: Edit the theme
Plugins are convenient, but they also carry processing overhead with them that can affect site performance. If you prefer not to use a plugin, you can edit the WordPress theme directly to enable Piwik.
One disadvantage of editing the theme directly is that if the theme is updated, the Piwik modifications are overwritten. To avoid this scenario, you should use a
child theme instead of editing the base parent theme. For detailed information about how to set up a child theme in WordPress, please visit
http://codex.wordpress.org/Child_Themes.
To enable Piwik by editing the theme, follow these steps:
- Log in to your Piwik account as the administrator:
- On the top right of the page, click your administrator username.
- Under Manage, click Tracking Code.
- Under JavaScript Tracking Code, copy the entire text in the tracking code box, including the starting <!—Piwik—> tag and the ending <!—End Piwik Code—> tag.
- Log in to WordPress as the administrator.
- Under Dashboard, click Appearance, and then click Editor. The Edit Themes page appears.
- Under Templates, click Footer (footer.php).
- Locate the ending </body> tag. Just above the </body> tag, paste the tracking code snippet that you obtained in step 1.
- Click Update File. Piwik is now enabled for all pages on your WordPress site. To view site statistics, log in to your Piwik account.
For more information about Piwik, please visit https://piwik.org.
Related Articles
- Piwik
This article describes how to install the Piwik analytics platform using the Softaculous installer in cPanel.
- Installing Piwik manually
Learn how to manually install the Piwik analytics platform on your Webhost.Berlin account.
- Using Google Analytics with WordPress
Learn how to use Google Analytics with your WordPress site to obtain statistics about visitor traffic.