Repeat visitors as goal

I wonder if I’m missing something super-trivial or perhaps it requires something a little more complex…

I’d like to get a list of returning visitors from a particular campaign / referrer.

For example, for a paid campaign, I’d like to track how many users went back to the site (directly) at a later stage. This would be considered as some kind of a goal / conversion. Would also be nice to know which keyword they used on the first visit (via the campaign), to measure keyword performance in terms of this conversion.

Any suggestions on how to do it with piwik? (be it with an existing report, via the API, adding some tracking code etc)

Thanks in advance.

You can use Segmentation to segment all visitors who used a given Campaign or Keyword (or combination of both), see Segmentation - Compare segments of visitors - Analytics Platform - Matomo

You can also segment only visitors that converted a specific goal. Maybe that would help?

Maybe I miss something, but I’m not sure how I can use segmentation here.

The visitor comes to the site for the first time via campaign X with keyword ‘abc’. Next time they come to the site directly, with no keyword.

I want to find/report those second visits, and on those, the referrer is direct and there are no keywords. It only existed on the first visit. How can I correlate those two visits?

My initial idea was to use goal, e.g. via trackGoal(), but I only need to set the goal on the second visit, when this information (which campaign, which keyword) is not available. Is there a way to somehow extract it from the visitorId or something else?

Yes the solution is to call .trackGoal() when the following calls return the campaig/keyword:

Thanks again Matt for not giving up on me :slight_smile:

I’m still not sure how this will help though. When the visitor visits the first time after clicking on the campaign ad, all the details will be there, but that won’t count as a goal. This is because this is only the first visit. I want to mark it as a goal only on the second visit (which might then not have any of the campaign / keyword details, since those were only available on the previous visit)…

Hope I explain the issue correctly, or perhaps I just miss something very obvious.

or does it mean that the getAttributionX calls only use the cookie data from the FIRST visit?

You have to use “First referrer attribution”

Then, on the second visit, if he didn’t use another website or another campaign or search engine, then the getAttributionCampaignName() will return the referrer of visit number 1.

By default Piwik uses “Last touch attribution” so that wouldn’t work and need to call the JS function see linked faq

Alternatively you could create your own cookie and store the referrer, then read the cookie and call trackGoal()

Thanks again Matt,

Ok. Much clearer now. I am already using first referer attribuion. Or at least I hope I do. The documentation on that wasn’t clear whether I need to use setConversionAttributionFirstReferrer before EVERY trackpageview, or just once. I currently add it just-in-case before my trackEcommerceOrder as well.

Adding another cookie was already something I’ve had in mind, but just thought I could perhaps re-use some of the existing info in the piwik cookies.

I’ll try to play with it and see how it goes. Thanks again for your patience.

Sorry for nitpicking but what exactly did you mean in

if he didn’t use another website or another campaign or search engine, then the getAttributionCampaignName() will return the referrer of visit number 1
[/quote] ?

If I’m using first referrer attribution, shouldn’t it “stick”, regardless of which referrer/site/campaign the user came through on the 2nd/3rd/4th/nth visit??

hi Matt,

if I’m trying to get the Campaign a visitor first came in on, do I need to just call:




and ensure I’m using


everywhere for tracking? I don’t seem to be getting anything back by doing this. I was hoping to track actual adwords conversions to specific products.

thanks in advance

by default piwik should track campaigns and attribute to products automatically (assuming you used ), without using these functions? or are you trying to do something else?

hi Matt,

yes, Campaigns are tracking just fine. I’m just trying to extract from the tracking code if someone used a campaign key, and if so, recording it in another system against that user/action. When I test coming in with a campaign link, I then don’t see anything using the javascript outlined above -presumably I’m doing something wrong with the ordering of instructions?

when you test coming with campaign, you already created a visit in piwik, you have to wait 30minutes for a new visit/referer or set in config/config.ini.php


to TEMPORARILY force all page views as new visits for your testing

ok, just to check that I’ve got this correct in my head. I’ve got a server that I’m hitting our site from. I’ve not been on there today. I load up a page on that server:


I think click through to a link which is on another domain, but contains the same tracking code:


from this page, the below tracking code/javascript fires, and the alert prompts are empty. Is the problem with the script, or the change in domain? I thought the domain change was ok since we’re seeing other stats within the same piwik install/site for that second domain

tracking code:

var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 5);

var Campaign = piwikTracker.getAttributionCampaignKeyword();
var CampaignKeyword = piwikTracker.getAttributionCampaignName();
alert("Campaign: " + Campaign);
alert("CampaignKeyword: " + CampaignKeyword);   


The first party cookies are on a per domain basis so yes the domain change is expected to not carry the campaign info

can I just list that domain (#2) under the same site ID setup, and will it then work? Or do I need to change something else?

really appreciate your help on this -pulling campaign info onto the web page is the last piece in a puzzle we’ve been trying to finish for a couple of year now, on and off!

Happy New Year! If you are still using Piwik and interested in the awesome new feature of “Creating a Custom Segment in Piwik and apply to reports in Real time!” we need YOUR help, with a little or big donation at:

This will allow to dynamically add or edit, a new set of rules for example “Show all visitors from USA and using Firefox and using Google”. This will be done via a simple to use interface. See screenshots and more info here:

We are crowd funding the future of Piwik and this feature in particular. With your help we can do it.