WordPress: install a container (with a tracking code)

If you’re running your website on WordPress, you can add the Piwik PRO container using a plugin. First, you’ll need to add a site or app to Piwik PRO. Next, install our plugin in WordPress and set it up. In this article, we’ll show you how to do it.

Add a site or app in Piwik PRO

To add a site or app in Piwik PRO, follow these steps:

  1. Go to Menu > Administration.
  2. Navigate to Sites & apps.
  3. Click Add a site or app.
  4. Type the site or app name and address, and click Save.
    Site or app address (Administration)

    Note: If you want to track a few domains with the same tracking code, add their addresses.

  5. Set the time zone and currency.
    Time zone and currency (administration)

    Note: We’ll show data in reports in this time zone. We’ll use this currency for goal revenue.

Install a container with the WordPress plugin

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

To install the tracking code with the WordPress plugin, follow these steps:

  1. In your WordPress admin panel, go to Plugins > New Plugin.
  2. Search for Piwik PRO or install the plugin form wordpress.org.
  3. Click Install now.
  4. Click Activate.
  5. Go to Settings > Piwik PRO.
  6. Type in the container address (URL).

    Note: Enter your Piwik PRO account address with containers added to the address.

    • For standard domains: https://yourname.containers.piwik.pro
    • For custom domains: https://yourname.piwik.pro/containers

    This address may be different for Piwik PRO on-premises or private cloud accounts. Contact us to get the right address.

  7. Type in your site ID. Where to find it?
  8. Leave Basic container (asynch) checked. This container holds your tracking code and is used to handle most tags.
    Basic container (on) in the WordPress plugin

    Note: Make sure your WordPress theme has the wp_body_open() function right after the opening <body> tag, otherwise the container won’t work.

  9. Check Additional container (sync) if you want to add the container for sync tags.
  10. Optionally rename the data layer.
    Data layer in the WordPress plugin

    Note: Rename the data layer if you use other software with data layers. If the names are the same, the software can interfere with each other.

    To check if your data layer name is not used by other software on your site, follow these steps:

    • In the console on your site, run this command: !window.hasOwnProperty("customDataLayer"); replacing customDataLayer with your custom name.
    • If this command returns true, then you can safely use your custom name.
  11. Click Save changes.
  12. Data will appear in reports in about an hour. Data in the tracker debugger will appear instantly.

    Tip: You can also check manually if the tracking works. Read more

Tip: To change how your data is collected, you can use the following settings:

Support the Content Security Policy mechanism

Content Security Policy restricts third-party tools from loading codes on the website and allows to fetch only approved origins of content. To support the Content Security Policy mechanism when using our WordPress plugin, you need to add a nonce value as an attribute to containers and scripts that these containers load.

To add a nonce value, follow these steps:

  1. Add to a function.php file in your theme the following code:
    add_filter( 'piwik_pro_nonce', function() { 
        return wp_create_nonce( time() ); 
    } );

Tip: For more information, read our article about Content Security Policy.

Was this article helpful?

Technical support

If you still have some questions, visit our community.
There’s always someone ready to help!

Back to help center