Manual Goal Tracking with Image Tracker - Detection of same User before Cookies

Hello everyone,

I have a question to manual goal tracking using the image API.

One can use piwikTracker.trackGoal() (if synchronous tracker used) for manual goal tracking with the JS tracker, or, alternatively TWO image tracker calls to achieve the same goal. (Two because otherwise only the goal will be logged on a call with “idgoal”, not the also provided “action_name”. So that one needs to separate “idgoal” and “action_name” in two different image tracker calls for both to be logged. That is also the way the JS tracker does it – it also makes two calls if piwikTracker.trackGoal() is set.)

I use the following tracker for manual goal tracking:

<script type="text/javascript">
	<img src="" style="border:0" alt="" />
	<img src="" style="border:0" alt="" />

Specifically, I use that to track error pages (e.g. 404), to track broken links, etc. And use negative goal value for that. :slight_smile: It’s a hobby website, but I guess that commercial websites would have the same problem.

When a new user with disabled JavaScript (e.g. a user of the NoScript browser extension, some bot, etc.) visits the above page, the two above image tracker calls result in logging of two different visitors in Piwik. (Tested with Firefox.)

Reason seems to be: Both calls are issued before the visitor gets a cookie set, so that Piwik doesn’t detect both calls as coming from the same visitor.

Subsequent calls will then be detected as coming from the “second” visitor. With only the first call (the achieved “goal”) appearing with the “first” visitor.

That problem does not occur with the JS tracker, seemingly because it uses following additional parameters on the call: “id”, “_idts” and “_viewts”. With them set to the same values on both calls and therefore the calls detected as coming from the same visitor. Their values also appear in the “_pk_id…” cookie.

How can I bring Piwik to detect both above calls as coming from the same user?

My guess would be using (maybe some of) the above “id”, “_idts” and “_viewts” parameters. (E.g. setting their values to something like hashes of IP address+User Agent string+various other request headers (all being available in PHP.) BUT: I do not want to implement visitor tracking in my application by completely side-stepping Piwik cookie-based visitor management. I only want the two above first calls to be detected as coming from the same user, until the Piwik cookie-based management kicks in. How could that be done in an officially supported way?

What’s the reason for the need to separate ”idgoal” and “action_name” in two calls? Why can’t Piwik log both when both are provided on the same call?
A side effect of using two calls is also that their log order varies – sometimes the goal appears before the “action” in the log, and sometimes after it. (At least with my lame shared host, with largely varied server response times to the above separate calls.)

Thanks in advance!

I think in this case problem happens because both requests start/arrive at the same time, and server is running both at same time creating two visits. If you put 1 second between each image, this would fix it.

Hi matt, thanks for the response. I think you mean a delay using JS, which would work with JS enabled (and it actually seems that the same effect of logging two separate visitors occurs with the Piwik JS tracker too), but I use the above image tracker when JS is disabled in the browser.

Any chance that Piwik could be updated to log ”idgoal” and “action_name” on one single request instead of currently two?

Anyway, this is not a big deal for my purpose. Just for my info.

Yes you can send a bulk request:

but it requires to set the token auth which is not desired in your case…

Hi matt, thanks for your feedback. You are right, I’d rather not reveal token_auth to random visitors. :slight_smile: I’ll leave it as it is, it’s good enough for my purposes.

Just some feedback to the bulk tracking documentation in :
It looks like the sentence “The object should contain the following properties:” needs to be changed to “The object must contain the following properties:”, if its a hard requirement and not just a “nice to have”.

thanks, fixed