Ticket #1984 (closed New feature: fixed)
Custom Variables support: new JS API and new reports
| Reported by: | matt | Owned by: | matt |
|---|---|---|---|
| Priority: | critical | Milestone: | Piwik 1.2 |
| Component: | Core | Keywords: | |
| Cc: | Sensitive: | no |
Description (last modified by matt) (diff)
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
- Count Logged in users VS logged out visitors (or Customers VS prospects)
- Count custom things per visit that are not included in Piwik standard metrics, eg. 'games played', 'comments left', or anything etc.
- Track position of keywords in google search page (using new parameter found in ref url recently after quick parsing of ref url in JS)
Custom data: New default reports
- Custom Variable: list all distinct names, for each list visits, pages, time on site, bounce rate, etc.
- On click on any variable name, list all distinct values for this custom variable with same metrics.
This new report could be displayed in "Visitors > Custom Variables"
Custom data: JS API piwik.js
- new .setCustomData(index, name, value)
- new .getCustomData(name)
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.
Performance impact
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
- Update Live! widget and visitor log to show the custom variables set
Please submit any feedback/question.
