Sending custom JSON data to the piwik.php tracking scripts doesn't work


(mduet) #1

Hi.

I’m running piwik 0.4 and I would like to send custom data to piwik in order to track additional visitor data in piwik.

But when I try this (like it’s described in DOC) the page request isn’t tracked at all because of a JS Error.

The JS I’m using on test a page:
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + “piwik.php”, 1);
var myCustomObj = { “property1” : “value1” };
piwikTracker.setCustomVars( myCustomObj );
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {
var dbg=“ERROR.\n\n”;
dbg+="err: " + err+ “\n\n”;
alert(dbg);
}

The Error:

TypeError: piwikTracker.setCustomVars is not a function

Please help.


(mduet) #2

It’s pretty simple style_emoticons/<#EMO_DIR#>/rolleyes.gif style_emoticons/<#EMO_DIR#>/wink.gif

The function to use is named “setCustomData” and not “setCustomVars”.

This is just a misstake in the DOCs on (http://piwik.org/docs/javascript-tracking/).

var user = { ‘userId’ : user_id }; piwikTracker.setCustomVars( user );

Should be:

var user = { ‘userId’ : user_id }; piwikTracker.setCustomData( user );

(vipsoft) #3

Good catch.


(Matthieu Aubry) #4

i updated the docs ; vipsoft if you’d like access to the website we can discuss it :slight_smile:


(Matthieu Aubry) #5

FYI, I will be working on putting ‘Visitor custom variable’ in Piwik in the next release. Keep an eye on the ticket: Custom Variables support: new JS API and new reports · Issue #1984 · matomo-org/matomo · GitHub or the next release.