Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Custom Variables support: new JS API and new reports #1984
FEATURE RELEASED in Piwik 1.2
See the documentation in: Web analytics - Tracking Custom Variables
The goal of this feature is to put visits into buckets (segments) via the Piwik JS API. Then access reports about these custom name/values just like other reports in Piwik.
Custom data: Use cases
Custom data: New default reports
This new report could be displayed in "Visitors > Custom Variables"
Custom data: JS API piwik.js
We should allow for up to 3 custom variables (GA does 5 but 3 will be fine!).
This up to 3 (key,value) pairs will be stored in 1st party cookie.
For a given index, name should always be the same.
Scope of cookie is session scope (dies when browser dies).
The content of the cookie is passed to piwik.php (c1n=custom_name_1&c1v=custom_value_1 etc.?).
The name,value pairs should be limited in length to not excell the URL limit (they are send on each page view along with current URL, page name and possibly url ref and more).
Setting a custom var with the same slot in a subsequent page view will overwrite previous value set.
Also update PHP Tracker API with these new methods.
Custom data: Schema update
Add 6 fields to the log_visit table: custom_name_1, custom_value_1, custom_name_2, custom_value_2, etc.
name and value are the parameters to JS function piwik.setCustomVar(1, name, value)
Custom data: Tracker update
New visitor and existing visitor will set the custom variable if passed.
Custom data: Archiving
The new reports (see above) require couple new queries.
Custom data: API
New API function released to report the custom data names and values, similar to existing functions.
When no custom var is set, this should not affect the speed (ie. no performance regression in normal use case). Check this is the case.
For each custom variable, distinct values should be kept low whenever possible (eg. 10 or 20 disctinct values).
Nice to have
Please submit any feedback/question.
If I understand correctly, this busts the existing setCustomData() by moving the key-value storage into piwik.js.
What is "index"? Is that a namespace? (e.g., corresponds to the Plugin's name?) Shouldn't it also be present in getCustomData()?
I suggest we keep the existing json_encode() rather than splitting up into separate parameters.
Replying to vipsoft:
It provides 'potential' page level scope, if the custom data was recorded (which is not the case at this stage). However this ticket will actually implement it for the session level (ie. update schema, new report & API). I think we agree :)
See interesting article at http://www.roirevolution.com/blog/2010/12/ecommerce-with-custom-variables.php
(In ) Refs #1984 - New plugins CustomVariables
To finish the ticket, this is pending first party cookie implementation JS API updates required for the following:
basically, nameId and name must always match, so that we always record the custom variable name,value in the same 'slot' in the database. This is similar to GA implentation.
nameId is integer,
(In ) refs #409 - first party cookies
refs #739 - piwik.js improvements
refs #752 - track middle mouse button clicks (via mousedown+mouseup pseudo-click handler); defaults to tracking true "clicks"
refs #1984 - custom variables vs custom data
@todo These are just stubs.
(In ) Refs #1984
Still to do:
(In ) refs #409:
refs #2078 Webkit bug ("Failed to load resource") when link target is the current window/tab
Ok, but setCustomData() need to be kept - not only for unit tests, please.
I have integrated setCustomVariables in the Piwik for Drupal module, but still have some questions.
I updated the Custom Variables documentation with the following