Multi-value custom variables in one call?


#1

Hello,

getting used to Piwik and so far so great! Have a couple questions

I have been going through the docs and phorums and I can’t figure this out.

Goal

Pass multiple custom values to one custom variable without having to call multiple trackpageview.

Issue / Assumptions:

I don’t want to call trackpageview more than once because it artificially (and I believe incorrectly) bloats our pageviews.

It gets worse with Async because it tracks the multiple page views but not the multiple custom values(outlined below)

From the Docs:

For example, for a “News” website or blog, a given article might be categorized into one or several categories. In this case, you could set one or several Custom Variables with name=“category”, one with value=“Sports” and another with value=“Europe” if the article is classified in Sports and Europe Categories. The Custom Variables report will then report on how many visits and page views were in each of your website’s categories.

Target Code


piwikTracker.setCustomVariable (1,Category','Sports', 'page');
piwikTracker.setCustomVariable (1,'Category','Europe', 'page');
piwikTracker.trackPageView();

My Results

These are deltas I am seeing and not exact numbers

Custom Variable name - Category Visits - 1
Custom Variable value - Europe Visits - 1
Actions - Pages mytestpage.html - Pageviews - 1

Alternate Code


piwikTracker.setCustomVariable (1,Category','Sports', 'page');
piwikTracker.trackPageView();
piwikTracker.setCustomVariable (1,'Category','Europe', 'page');
piwikTracker.trackPageView();

My Results

These are deltas I am seeing and not exact numbers

Custom Variable name - Category Visits - 2
Custom Variable value - Sports Visits - 1
Custom Variable value - Europe Visits - 1
Actions - Pages - mytestpage.html - Pageviews - 2

Async Issue:

Doing the since multiple sets of custom variable does not result in multiple values being recorded. When I call track page view multiple times I see mutliple page views but only the last value being tracked where the sync version would track both values.


_paq.push(['setCustomVariable','1','Category','Sports']);
_paq.push(['trackPageView']);
_paq.push(['setCustomVariable','1','Category','Europe']);
_paq.push(['trackPageView']);

My Results

These are deltas I am seeing and not exact numbers

Custom Variable name - Category Visits - 1
Custom Variable value - Europe Visits - 1
Actions - Pages mytestpage.html - Pageviews - 2

thanks.


(Matthieu Aubry) #2

The doc is not clear.

The code should be:


piwikTracker.setCustomVariable (1,Category','Sports', 'page');
piwikTracker.setCustomVariable (2,'Category','Europe', 'page');
piwikTracker.trackPageView();

You have to use a different slot, and you need to call trackpageview() only once. This should work?

please confirm and i’ll update the doc


#3

ahhh yes that does make it much clearer thank you


(Matthieu Aubry) #4

Cool, i’ve updated the doc at http://piwik.org/docs/javascript-tracking/#toc-custom-variables