WordPress: install a tracking code

If you’re running your website on WordPress, you can add a Piwik PRO tracking code using a plugin. First, you’ll need to install the plugin, and then, add the URL of your account in Piwik PRO and the website’s ID and adjust the setup. 

In this article, we’ll show you how to install a tracking code on a WordPress site.

Before you start

Before you start setting up tracking, here are some basic things you should know:

  • Piwik PRO uses a container that holds a tracking code. The container is used by Piwik PRO Tag Manager to fire custom code on your website. The tracking code is a tag, called Piwik PRO tag, sealed in the container.
  • You can change how the tracking code collects data using options in the Piwik PRO tag in Tag Manager or modify the code via JavaScript API.
  • Piwik PRO uses two types of containers: for asynchronous tags and synchronous tags. Always install the container for asynchronous tags — this code will collect accurate data. If you plan to use tags for A/B tests, install both codes on your website. For more, read this article.
  • Add a website or an app to Piwik PRO.

Install the plugin in WordPress

Note: You need to have an administrator role in WordPress to add and manage plugins.

To install the Piwik PRO plugin, follow these steps:

  1. Log in to WordPress.
  2. Navigate to Plugins.
  3. Click Add New.
  4. Type Piwik PRO Tag Manager Integration into the search box.
  5. Click Install Now.
  6. Once the plugin is installed, click Activate.

Set up the plugin

After setting the plugin as active, you need to add the URL of your account in Piwik PRO and the website’s ID and adjust the setup. The configuration will be different for the container code for asynchronous tag and the container code for synchronous tag.

To set up the plugin, follow these steps:

  1. Log in to WordPress.
  2. Navigate to Settings.
  3. Pick Piwik PRO Tag Manager integration from the setting list.

  4. Container code for asynchronous tag (required)

  5. Navigate to Include tags in body section.
  6. In Server URL, enter the address of your account in Piwik PRO ending with /containers. For example, clearbank.piwik.pro/containers.
  7. Note: This setup won’t work for Piwik PRO On-premise STS and LTS. If you have this type of account, reach out to your dedicated contact person at Piwik PRO to confirm the server URL.

  8. Copy your website ID from Piwik PRO. To find the ID go to Piwik PRO > Menu > Administration > Websites & apps and pick your website. The ID is under the website name.
  9. In Website ID, enter the ID of your website.
  10. Mark wp-body.
  11. Note: The container code for asynchronous tags should always be placed right after the opening <body> tag. Mark wp_body, when you’re sure that your theme has <?php wp_body(); ?> element. If you’re not sure, mark output buffering.


    Container code for synchronous tag (optional)

  12. Navigate to Include tags in head section.
  13. In Server URL, enter the address of your account in Piwik PRO ending with /containers. For example, clearbank.piwik.pro/containers.
  14. Note: This setup won’t work for Piwik PRO On-premise STS and LTS. If you have this type of account, reach out to your dedicated contact person at Piwik PRO to confirm the server URL.

  15. Copy your website ID from Piwik PRO. To find the ID go to Piwik PRO > Menu > Administration > Websites & apps and pick your website. The ID is under the website name.
  16. In Website ID, enter the ID of your website.
  17. Mark wp-head.
  18. Note: The container code for synchronous tags should always be placed inside <head></head>. Mark wp_head, when you’re sure that your theme has <?php wp_head(); ?> element. If you’re not sure, mark output buffering.

  19. Adjust other settings.
    • Dependencies: You can define dependency scripts that should be loaded before the Piwik Pro container code. This works only if you marked wp_body or wp_head method.
    • Cache: You can turn on or off a mechanism that serves the script from a cached file. And then set:
      • Time: Refresh interval time (in minutes).
      • Rewrite Rewrites the script’s URL (.htaccess modification is required).
      • Clear: Deletes all cached files and directories.
    • Version: You can turn on or off a mechanism that adds the query parameter ?ver= to the script’s URL.
    • Snippet: You can adjust this plugin to the Piwik PRO Tag Manager older than 1.16.0.
  20. When you’re done, click Save Changes.

Note: If you’re tracking several domains or subdomains under one website in Piwik PRO, you need to install and set up the plugin on each website.

If everything is set up correctly, you’ll see data in Analytics in about one hour. Yet, if you want to manually check that tracking is working, follow these guidelines.

Was this article helpful?

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!