By default, tracking campaigns in Piwik involves adding the required parameter pk_campaign (and optional parameter pk_kwd) to the URLs pointing to your website. Piwik also supports Google Analytics campaign parameters (utm_*).

Here is a comma delimited list of default parameter names that Piwik will read:

 campaign name parameters: pk_campaign, piwik_campaign, utm_campaign, utm_source, utm_medium
 campaign keyword parameters: pk_kwd, piwik_kwd, pk_keyword, utm_term

It is also possible to customize these parameter names. For example, we would like to use the parameters names “campaign” (instead of pk_campaign) and “keyword” (instead of pk_kwd). To do so, there are two required steps:

  • 1) Override the parameters in the config file. In your config/config.ini.php, add the following:

    [Tracker]
    campaign_var_name="campaign"
    campaign_keyword_var_name="keyword"
    

Note: you may specify a comma separated list of campaign parameter names, in case you wanted Piwik to read the campaign name or value from several possible parameters. The first non empty value will be used.

  • 2) Customize the parameters in the Javascript. In the Javascript snippet on all your pages, add the following before the trackPageView() call:

    _paq.push(['setCampaignNameKey', 'campaign']);
    _paq.push(['setCampaignKeywordKey', 'keyword']);
    

Note: these two functions also accept an array of strings. If an array of names is specified, the first non empty campaign or keyword parameter value will be selected.

Note: the Campaign parameters can be used in the query string or in the hash as well (for cleaner canonical URLs), such as: “landing.html#pk_campaign=my campaign”