Skip to content


Subversion checkout URL

You can clone with
Download ZIP


For a visit via a campaign, if the campaign keyword is not set, detect keyword from Referrer URL #517

mattab opened this Issue · 17 comments

4 participants


Bug report:

When a visitor comes and a campaign “name” is detected, there are sometimes no “keyword” set. Instead of leaving the value empty, we could try to fill up the gap and:

  • try detect the keyword from the Referrer URL if it is found there (ie. if a search engine was used)
  • if no keyword could be detected from the ref URL, set the “campaign keyword” as the domain hostname. This way it will give an easy breakdown of referrer website URL for campaigns.

This would improve the campaign tracking data quality.

Google Adwords tracking would also work better and give more accurate data.

  • See new [Tracking Campaigns](
  • [URL Builder tool](
  • Official piwik campaign parameters names are now: pk_campaign and pk_kwd (consistent with cookie prefix, better than piwik_ prefix)
  • New FAQ: [“Does Piwik support Google Analytics campaign parameters (utm_campaign, utm_medium, utm_source, utm_term)?”](
  • New FAQ: [“How do I customize the Piwik Campaign parameters pk_campaign and pk_kwd?” ](

No worries I'll give this a shot with a small adwords account I am playing with. Though I also have some more advanced idea's for tracking adwords without auto-tagging and thus giving more functionality in other area's.

Will test this out firstly and go from there.


marc, sounds good; let us know if you find any bug or issues, this has never been tested, but we want this to work perfectly and with an easy to use documentation; I think we can assume that we need adwords to be auto tagged using landing keyword, etc.


Hey Matt,

Not really. There are other less obvious to others, ways to track adwords that still keeps your data private.

See bots and others can crawl and track adwords adds and backwards engineer what you are bidding on. Do that every day over a period of time and you have a clear picture of what keywords are profitable for someone in what industry.

I'll test it out on auto-tagging and then discuss privately the other concepts and decide if you want to introduce those.

Of course there could be both options, auto-tagging and then the privacy option :D

Talk Soon


example adwords url 

From forum post

Generally, Adwords links seem to look like this: 

I made some test for a few days with an adwords account. Adwords reports 5 clicks and I see 5 clicks in the Piwik DB, good start. But 1 didnt have the referer set, 2 others were from google &, 2 from Google display (adsense).

The only way to track Adwords properly is to have users enable auto tagging in their account:

Then landing page URLs have the parameter 'gclid' which is how we detect that the user is coming from adwords.

Alternatively (AND / OR), Users can 'manually' tag their landing pages, then they simply can use the standard Piwik campaign feature #604

Then we can look at the ref URL

  • If google (or Ask or other SE) then it is Google Search Network, with given keyword
  • If domain = then it is Google Display Network In the "Display" case, the ref URL looks like this:

The parameter 'url' gives the URL where the click comes from. This is important to report it in Piwik since adwords advertisers would want to ban domains that have poor conversion rates from their Display pool.

Maybe a good way to report Adwords in Piwik would be:

  • on each page view in Piwik, check if URL contains gclid
    • if it does contain, AND there is no standard Piwik campaign parameters (OR GA campaign parameters), check referer:
    • if referer not empty and is OR is a known search engine (big search engines have deals to display adwords on their search result pages)
    • we have detected a click from Adwords (ie. that we are paying for)
    • if this is a new visit OR if an existing visit with empty referer, then we record adwords as referer type 'campaign'
    • Set campaign = 'Google Adwords - Display Network', keyword = URL parameter from referer
    • OR set campaign = 'Google Adwords - Search Network', keyword = KWD detected in the referer

See google search network:

and google display network:

interesting page:


  • update the Tracker algorithm to properly detect adwords search/display
  • Link the 'Campaigns' Referer report from the Referer Overview report
  • Ensure that logos are displayed in the campaign report like normal organic search
  • Create a FAQ answer to explain that this is working, that auto tagging must be enabled, etc.
  • Create a FAQ answer to explain how to track Campaigns in Piwik #1042
  • Update the Goal Tracking documentation and clarify that Goal conversions will be reported also for each Adword referer (ie. 'Adwords / keyword 'web analytics' has convertion rate 5%). Put a screenshot in the doc.

Any other suggestion / idea, please comment


on a related note...


Claryfying & Restricting the scope of this ticket

This was the previous ticket description:

Piwik currently support campaigns and keywords for campaigns, but this support hasn't been tested with Adwords use case. This ticket is mainly about testing the support with real data, making sure that adword campaigns, when url tagging is enabled (see in adwords), piwik will detect the campaign name, the keyword from the referer or pick it up from the tagged URL, etc.


You need to enable auto tagging in your adwords campaign. "Google Analytics makes it easy to track your AdWords referrals effortlessly using the auto-tagging feature. Auto-tagging is enabled by default when you link your AdWords and Analytics accounts. To turn auto-tagging on or off at any time, update the checkbox in your Account Preferences from your AdWords My Account tab. Using auto-tagging allows you to bypass the steps to tag the URLs of your AdWords advertisements."

In Piwik, you can tag your links with two variables:

    * Campaign name (identifier of the campaign). This parameter is by default called piwik_campaign
    * Campaign detail (for example, the banner name). This parameter is by default called piwik_kwd 

When you enable auto tagging in adwords specifying the parameters names piwik_campaign and piwik_kwd, your visits coming from Adwords will be tracked in Referers > Campaigns. You will see how many visits, bounce rate, page views for each campaign and keyword. Also, if you have setup goals, you can see conversion rate and revenue per goal, for all your Adwords campaigns.

'''Parameter names'''

You can change the parameter names by setting the following in the config/config.ini.php and replacing by the name you wish to use.

; variable name to track the campaign name
campaign_var_name = piwik_campaign
; variable name to track the campaign detail (eg. keyword)
campaign_keyword_var_name = piwik_kwd

'''Note: missing feature'''

"when i track campaigns via "piwik_campaign" from adwords i got only the data from the campaign query but not the real searched keyword (referer)." Explanation: currently when a campaign is detected, it doesn't try to load the keyword from the referer. This is a bug (or missing feature). What we can do is: when the campaign keyword is not specified in the landing URL, we can automatically load the keyword from the referer if found. 


We also need a user guide on 
 * How to use campaigns in Piwik? (see [604 documentation example for tracking newsletter]) 

See also #476 for tracking adsense ads or yahoo content network.


(In [7811]) Refs #517, search for campaign keywords in referrer URL when not supplied by query param and use referrer hostname when no keywords in referrer URL and nothing supplied in query param.

Note: also includes quick tweak to integration test base for more descriptive error when expected file cannot be found.


(In [7812]) Fixes #517 if a campaign name is set, we will try to fill in the keyword with the publisher Url (when visitor came from adsense ad) or with user keyword (when coming from adwords)


I have also problems with tracking AdWords campaigns. This issue is closed, but the problem seems to be not solved yet. I see lots of "" referrers in my statistics. They are not detected as campaigns. The referrer URLs are of the form in #476. There are many parameters in the link, but parsing at least the "url=..." would be nice.

I would also like to help with coding, just tell me what would be the best way to implement this in Piwik.

Thanks a lot,


I have found a workaround:

--- core/Tracker/Visit.php.orig 2013-10-14 10:42:00.000000000 +0200
+++ core/Tracker/Visit.php  2013-10-15 14:46:16.411174133 +0200
@@ -1703,6 +1703,12 @@

+        if (empty($campaignName) &&
+            strpos($this->refererHost, 'doubleclick') !== false
+        ) {
+            $campaignName = "AdWords";
+        }
         if (!empty($campaignName)) {
             $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_CAMPAIGN;
             $this->nameRefererAnalyzed = $campaignName;

The original code did not work because the pk_campaign parameter was not set for our AdWords campaigns. This way, every visit from doubleclick host is considered as the AdWords campaign and the referring sites are encoded as campaign keywords.


thanks for the suggestion. Could you send me an example of a Adwords URL and an example of a Adsense URL ?

I think it would be best to set the campaign name to either Adwords or Adsense depending on the referrer URL.


Thanks Matt, I sent you the URL examples to your email. Don't know if there is any secure info in the url parameters.

There is an url parameter "adsense_enabled", which is always true in our links, so I don't have any examples of Adwords (no Adsense) urls.


In d542986: Fixes #4261 Refs #517 Properly attribute to Adwords those visitors that come from a click on adwords


see also #4468 when &gclid= parameter found, mark visitor as Adwords

@mattab mattab added this to the 1.11 - Piwik 1.11 milestone
@mattab mattab self-assigned this
@sabl0r sabl0r referenced this issue from a commit in sabl0r/piwik
@mattab mattab Fixes #4261 Refs #517 Properly attribute to Adwords those visitors th…
…at come from a click on adwords
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.