Tracking search terms for adword campaign

Hi,

I’m currently setting up Piwik but I have a problem getting the data I need about my adword campaigns:

I am aware that I can manually set up campaigns and that I can dynamically insert the keyword which has been clicked by using {keyword}.

The problem is: I don’t need the keyword but the actual search term. Let’s say I would have booked “piwik” with broad match in adwords and someone is looking for “piwik demo”. My ad will be shown due to broad match but instead of telling me in Piwik that the user originally searched for “piwik demo” I will just get the keyword information - “piwik”.

So instead of getting the Google valuetracker information about the keyword I would need to analyse the referrer just as it’s done for organic traffic but still connect this to a campaign I have set up manually (just as the dev team intends to do completely automatically with #517) to differentiate organic and paid search terms.

Any suggestions to enable this?

Thanks a lot,
Sascha

Maybe there is an adwords special {tag} for the keyword you are looking for?

As far as I can tell Google only forwards the booked keyword which might be a broad match term but not the search term which actually caused the ad to appear.

The only way to get the search term is by analysing the referrer. What’s really strange is that Piwik can actually analyse this information. In that case however all search terms are put together with organic search terms. To differentiate organic from paid search I have to set up a campaign. As soon as I do this the referrer information seems to be discarded.

I had the same problem and implemented a quick and dirty fix. Now if the campaign keywords are empty, piwik analyzes the referer url and uses the original search strings from the referer as campaign keywords.

In “core/Tracker/Visit.php” I changed the function “detectRefererCampaign” in class “Piwik_Tracker_Visit_Referer” to this:


protected function detectRefererCampaign()
	{
		if(isset($this->currentUrlParse['query']))
		{
			$campaignParameters = Piwik_Common::getCampaignParameters();

			$campaignNames = $campaignParameters[0];
			foreach($campaignNames as $campaignNameParameter)
			{
				$campaignName = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignNameParameter);
				if( !empty($campaignName))
				{
					break;
				}
			}

			if(!empty($campaignName))
			{
				$this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_CAMPAIGN;
				$this->nameRefererAnalyzed = $campaignName;
				$campaignKeywords = $campaignParameters[1];

				$i = 0; //mychanges
				$num_elements = count($campaignKeywords);//mychanges
				foreach($campaignKeywords as $campaignKeywordParameter)
				{
					$i++;
					$campaignKeyword = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignKeywordParameter);
					if( !empty($campaignKeyword))
					{
						$this->keywordRefererAnalyzed = $campaignKeyword;
						break;
					}
					elseif ($i == $num_elements) {//mychanges
						$searchEngineInformation = Piwik_Common::extractSearchEngineInformationFromUrl($this->refererUrl);//mychanges
						Piwik_PostEvent('Tracker.detectRefererSearchEngine', $searchEngineInformation, $this->refererUrl);//mychanges
						if($searchEngineInformation !== false){//mychanges
								$this->keywordRefererAnalyzed = $searchEngineInformation['keywords'];//mychanges
								break;//mychanges
						}//mychanges
					}//mychanges
				}

				return true;
			}
		}
		return false;
	}

It seems to do what I want - however I haven’t used Piwik for long and am not that familiar with the source code, so there might be some side effects I am not aware of.

Hi murry,

thanks a lot - this could solve my problem!

Regards,
Sascha

Beware however that this is a change to a core file.

It would probably be better to make a plugin, but I haven’t had the time to figure out yet how those work yet.

Murry, thanks for the patch. I cross linked it from the related ticket about better campaign tracking: For a visit via a campaign, if the campaign keyword is not set, detect keyword from Referrer URL · Issue #517 · matomo-org/matomo · GitHub

You are probably on a very good track. if you can, please read the ticket and post your patch there if it’s the solution (or partial) to the problem and solutions exposed there? cheers

Hi murry,

Any luck with a plugin? I’ve changed the core file and it is working well but like you would be more comfortable with a plugin (plus don’t want to have to remember to change it again on update) :stuck_out_tongue:

I’m looking into plugin development now but if you’ve already started, I don’t want to duplicate your work…

Matt, what are the chances of this patch making it into the next release (and of piwik distinguishing between adwords referred traffic and normal search traffic, even when campaign parameters also exist in the querystring)?

Cheers,
Wilko

wilko, I would like to fix the ticket. IT would really help if you were able to post a comment on the ticket, explaining what your patch does, how to test it (example adwords URLs, etc.), what exact problem it fixes (ie. does it fix all problems mentionned in the ticket?), and commit a patch as explained in: http://piwik.org/participate/development-process/#toc-how-to-submit-a-patch

Then I promise I will commit it asap :slight_smile:

no probs - i’ll get on it :slight_smile: (it’s murry’s patch btw)

Hi wiljo,
Any hope to get this as a documented patch on the tracker, so it could be in piwik anytime soon ?

Has been almost a year since last activity :wink:

Best regards,

I’ve updated the ticket and increased priority in order to commit this change : For a visit via a campaign, if the campaign keyword is not set, detect keyword from Referrer URL · Issue #517 · matomo-org/matomo · GitHub