Sending Custom Variables to Tracker


(zeta) #1

Hi,

I don’t know if this feature is already implemented or being implemented in Piwik. Is there a way to track custom variables, such as when passed as a paramenter via the address link or something like that? This variable would be saved in a mysql database table.

I saw something at Piwik.js, a variable named _pk_custom_vars. Does it serve this purpose?

The purpose of this is to track websites with embedded content differently than the main website where the content is.

If there is nothing like it, is there a way to implement it via a plugin? Because I wouldn’t like to modify any of the core code.

Thanks.


(branica) #2

[quote=zeta @ Jan 15 2009, 01:54 PM]Hi,

I don’t know if this feature is already implemented or being implemented in Piwik. Is there a way to track custom variables, such as when passed as a paramenter via the address link or something like that? This variable would be saved in a mysql database table.

I saw something at Piwik.js, a variable named _pk_custom_vars. Does it serve this purpose?

The purpose of this is to track websites with embedded content differently than the main website where the content is.

If there is nothing like it, is there a way to implement it via a plugin? Because I wouldn’t like to modify any of the core code.

Thanks.[/quote]

I am not sure that I follow what exactly you need. But I think either campaigns and/or goals could accomplish what you are looking to do.


(dmorin) #3

I think the idea is that you could pass in information specific to the current user. For example, Woopra (Setup and Documentation — Woopra) lets you pass in a visitors name, email address, and avatar which are then stored and used to augment the interface. So instead of seeing Visitor #12345678, you see the person’s name. This is great from blogs or social networks where you capture that information through new comments or registrations. It can also be used to normalize user data by passing in a user ID or something so instead of just relying on cookies, you have this other piece of data that can tag a visitor.

The only reference I found to the extra fields in JS is from this post: http://lists.piwik.org/pipermail/piwik-svn…rch/000209.html

Makes sense but if we could get a quick code sample of how we can reference these fields from the plug-in, that would be great!


(mic) #4

[quote=dmorin @ Jan 16 2009, 01:50 AM]I think the idea is that you could pass in information specific to the current user. For example, Woopra (Setup and Documentation — Woopra) lets you pass in a visitors name, email address, and avatar which are then stored and used to augment the interface. So instead of seeing Visitor #12345678, you see the person’s name. This is great from blogs or social networks where you capture that information through new comments or registrations. It can also be used to normalize user data by passing in a user ID or something so instead of just relying on cookies, you have this other piece of data that can tag a visitor.

The only reference I found to the extra fields in JS is from this post: http://lists.piwik.org/pipermail/piwik-svn…rch/000209.html

Makes sense but if we could get a quick code sample of how we can reference these fields from the plug-in, that would be great![/quote]
I would also like to see some ‘custom’ fields which can be added to the variables.
Here i am talking the same as ‘dmorin’ suggested, but in this case for Joomla!.
There i have ‘unregistered’ and ‘registered’ users.
If a user is registered (which means he is already logged in) i have the user data (like id, username, etc.).
Now i would like to pass for example the id or the username to Piwik where i can see who visited my Joomla site.

At the moment there is only one other Joomla Extension which has this feature, but i would like to use Piwik!
If this feature would be possible, Piwik would be the #1 tracking tool for Joomla!

p.s.: i could then recommend Piwik to my customers and could finish the modules and plugins for implementation of Piwik into Joomla!

thx!


(toastbrot) #5

[quote=dmorin @ Jan 16 2009, 01:50 AM]The only reference I found to the extra fields in JS is from this post: http://lists.piwik.org/pipermail/piwik-svn…rch/000209.html

Makes sense but if we could get a quick code sample of how we can reference these fields from the plug-in, that would be great![/quote]

more clarifications here:
http://lists.piwik.org/pipermail/piwik-hac…rch/000636.html


(mic) #6

[quote=toastbrot @ May 4 2009, 02:13 PM]more clarifications here:
http://lists.piwik.org/pipermail/piwik-hac…rch/000636.html[/quote]

after having been kicked out by this forum 3 times (and lossing the post), here in short:

nice to see all those code fragments/patches/etc.

But they lead to nowhere!

To say it short and clear: if piwik wants to play on the bigger market and wants to become a big(ger) player, the developer(s) (or you might be the right person(s) should NOT holding back answer to our questions regarding hand-over custom variables.

It may be nice to now know that piwik can handle custom vars.

But where to store?
Makes not that sence to bloat the table _visits (makes as a side effect db.queries slow!).

So where can we (3PD) storing our custom vars?
Creating a new table inside piwik (where it is only ccessable either by piwik or a bridge)?
Creating a new table (or use an existing) in our CMS (or whatelse the target might be) - but now not accessable by piwik?

Would be nice to tell us all the secret behind this …

Thanks!


(vipsoft) #7

You do realize that Piwik is open source, right? All the code is there for you to see. There’s no obfuscation.

I’m a little surprised by the suggestion that we’re hiding features.

setCustomData() and where customData is an optional parameter is documented in the JavaScript tracking API. http://piwik.org/docs/javascript-tracking

Tracker.Visit.isExcluded is the event hook called on every page view. A plugin that wants to capture custom data can use this hook.
http://dev.piwik.org/trac/wiki/Plugins/Hooks


(mic) #8

[quote=vipsoft @ Jun 14 2009, 03:31 AM]You do realize that Piwik is open source, right? All the code is there for you to see. There’s no obfuscation.

I’m a little surprised by the suggestion that we’re hiding features.[/quote]
I am sorry for my previous wording.
With ‘… hiding …’ i did not ment that you are hiding features etc.
I meant more the procedures, API-calls - general the informations and guidelines 'how will work this … or this … etc.'
Now it is like ‘searching - searching - and maybe finding (at several places)’.

It would be easier for us all (you and us) if there would be a general place where all those questions about the API (and here specially ‘how to submit custom data(s) AND how to call them later inside Piwik AND where (how) to store them’.

I want to see (and it seems others too) clear and well commented samples.

Finally - discussed already in another thread here - the consistency of all documents (see also my tracker item there).

You are fully right if the Piwik developers are proud that Piwik is downloaded 100.000 times.
But this figure does nothing say about how many times it is really installed AND used.
What i want to say, if a look here into the forum, there are not so many questions about … (something) in relation to the download figure.
But here are several questions about 'how to catch custom data, how to store them (in the db) and how to show them later/handover (in Piwik or the the own system like any CMS, etc.)

For me, i am a Piwik fan and recommend it to everybody who owns a website AND is a bit more then a ‘normal user’ or novice.
And that figure is quite a bigger one (installed already and running at approx. 40 websites).

So - finally - i have to excuse myself if it sounded ‘offensive’.
Was not my intention!

(now i am copying this text (and pasting it again after new login), because i know already that this system has logged my out in the meantime!)
Please change the forum settings!
Seems that you have changed tese settings - thank you.


(Matthieu Aubry) #9

[quote=vipsoft @ Jun 14 2009, 02:31 AM]Tracker.Visit.isExcluded is the event hook called on every page view. A plugin that wants to capture custom data can use this hook.
http://dev.piwik.org/trac/wiki/Plugins/Hooks[/quote]

there are also a few more hooks available, and we could also add new ones; you just have to ask and justify the new hook request.Thanks


(Gaz) #10

In addition to click stream tracking, it would be really cool if we could add metadata to sessions and pages in the form of tags, then do queries on this in the future.

An example of tagging a session could be adding “forumuser=Gaz” via the javascript tracking code added by the forum software’s login page, we could then look at the different operating systems, web browsers and screen sizes that Gaz uses. Because the forum has linked my user to my cookie, my click streams outside the forum have a name associated with them.

Tagging pages could work in a similar way. Blog software plugins inject their tags to pages in piwik, then we can look at the most popular categories, who likes them and so on.

Apologies if something like this already exists, or is planned.


(moraine) #11

Hi all,
my interest has been spurned by your discussion. So I tried some small hack style_emoticons/<#EMO_DIR#>/wink.gif

What did I do?

First of all, I added a new column to the table “piwik_log_visit”. I named it “username”.
As my websites are mainly visited by Users known to me, I edited the table “piwik_log_visit” and entered the username with the visits I could identify.

Next I edited core/Tracker/Visits.php
I created a function

         * Returns the visitor's username
         *
         * @return varchar
         */
        protected function getVisitorUsername()
        {
                return $this->visitorInfo['username'];
        }


and inserted a call where needed ($visitRow =, $country =, $this->visitorInfo = array)
Most interesting for me was adding it where piwik checks wether we have a known visitor

                        if($visitRow
                                && count($visitRow) > 0)
                        {
                                $this->visitorInfo['visitor_idcookie'] = $visitRow['visitor_idcookie'];
                                $this->visitorInfo['visit_last_action_time'] = strtotime($visitRow['visit_last_action_time']);
                                $this->visitorInfo['visit_first_action_time'] = strtotime($visitRow['visit_first_action_time']);
                                $this->visitorInfo['idvisit'] = $visitRow['idvisit'];
                                $this->visitorInfo['username'] = $visitRow['username'];
                                $this->visitorInfo['visit_exit_idaction_url'] = $visitRow['visit_exit_idaction_url'];

                                $this->visitorKnown = true;

                                printDebug("The visitor is known because of his userSettings+IP (idcookie = {$visitRow['visitor_idcookie']}, idvisit$
                        }

Thus I ensured, that when a known visitor returns the correct username is added. So only new visitors remain without username - for me a small problem, as my websites have rarely new visitors.

I added the username then in some widgets, so I get the information displayed.

What my hack lacks? First of all, it is not integrated with the using websites. The username from Joomla, Gallery, WordPress, … is not used. First of all, I found no convenient way to do it. Either you change the tracking code (which would have to be made seperately for each website) or you try to retrieve it somehow from within piwik… I suppose hooks would be the best way to do it (Tracker.newVisitorInformation and Tracker.knownVisitorInformation). But it only works, when user log in to the website. As long as they don’t log in, we remain blind style_emoticons/<#EMO_DIR#>/wink.gif
The hack is not usable for websites with a lot of users.

If there is interest the small hack could be integrated into the core, although I think, it could be done more elegantly, than I did it.

lg
Andy


(Matthieu Aubry) #12

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.


(Matthieu Aubry) #13

This was released! Custom Variables Analytics - Analytics Platform - Matomo


#14

Hi,
our website has installed the old version of Piwik without customer variables.I want to now analyse the statistics with some customer variables of the old visitor log(e.g. the username),could you pls tell me where is the username saved?Or the information was not saved,should I grab the username from the database of the website?

Regards


#15

Hi,
our website has installed the old version of Piwik without customer variables.I want to now analyse the statistics with some customer variables of the old visitor log(e.g. the username),could you pls tell me where is the username saved?Or the information was not saved,should I grab the username from the database of the website?

Regards


(Matthieu Aubry) #16

Please upgrade to latest Piwik version!