Segmenting by Custom Variables Not Working

I can’t get the following url to return information:

index.php?module=API&method=Actions.getPageUrls&idSite=1&period=year&date=2011-07-05&format=xml&token_auth=(mytokenhere)&segment=customVariableName1==Version;customVariableValue1==1.6.19533

The CustomVariables.getCustomVariables returns Version as the first record in its result set and the CustomVariables.getCustomVariablesValuesFromNameId returns 1.6.19533 as the second record in its result set. This leads me to believe that the first url (Actions.getPageUrls) should work.

I want to segment the results of Actions.getPageUrls by my first custom variable (Version) with a value of 1.6.19533, but again, the getPageUrls url above is not working.

Any suggestions?

What does the customVariableValue number represent? When I change that to 2 it still does not work.

Thanks

Do you record this custom variable in index=1 ? customVariableValue1 will only match the visits that have a custom variable recorded in index 1

Yes, “Version” is recorded at index 1. We are using 3 custom variables, but “Version” is the first.

What you can do is try only with: segment=customVariableName1==Version
Does it return something?

then add the other condition?

That doesnt return anything either, just a blank page. Does the “scope” of the custom variable matter? We are using the “visit” scope (the one that corresponds to _cvar).

The scope does not matter, all custom variables are merged into this one report. What do you mean it return “blank”? It should at least return empty dataset for example

Yes, it returns <?xml version="1.0" encoding="utf-8" ?> , but no results. I know that theyre in there because of the information that the other two urls (above) returned.

Any ideas?

can you put a screenshot of the Visitor Log showing the custom variable (on the left) for the DAY that you also request the API and get no result? maybe there is a typo in your URL? It is supposed to work.

minibunson,

Were you able to get this resolved? I ran into the same problem, and noticed the columns for the custom vars in the log_link_visit_action table. In my case, they were all null. I was not specifying a scope in the setCustomVariable methods, looks like it defaults to ‘visit’. I added two lines to the JS tracking code for each of my params, one for each scope and I am now able to segment the new data by the custom var fields. Seemed a bit redundant, but it works for now.

edit:

Matt, just caught on what you mean by the custom variables being merged.

The issue is that I believe we were both looking to segment by a custom var on a report from the Actions api. Here, it does appear to matter what scope the custom vars are in. I tried the custom variables under both scopes, but that leads to it being double counted in the Custom Variables report as you mentioned above.

Hi, this is NOT working in 1.5.1.

I dug through the ENTIRE code base, and the query that is used to determine if there are any qualifying visits only checks VISIT scope custom variables.

So if you try to segment actions on page level custom variables it will never work.

This can be confirmed by reviewing the code in Period.php computeNbUniqVisitors() and examing the sql code generated. It only checks the log_visit table so any custom variables set on actions are not used in counting if there are any visits for this report.

OK segmentation for Actions.get* work only for custom var of scope “page”. See note in Segmentation - Compare segments of visitors - Analytics Platform - Matomo

Actions.getPageTitles is the report I am trying to segment. The code ends up back at ArchiveProcessing/Period.php which counts the number of visits that apply before generating the report and checks the Visit scoped custom variable, which of course does not exist.

I was able to get this working for my purposes. To get it to work, I had to make sure that every custom variable is being added twice, once with visit scope and once with page scope. The custom variable counts in the ui are wrong, but the counts when segmenting by custom variables are correct.

Matt,

Has this issue been resolved? I understand that you’ve said that Actions.get* only works with page scope, but even when I add custom variables with only a “page” scope and then try to filter by those custom variables it still doesn’t work. I am currently getting around this issue by adding both types of scope (visit and page) for every custom variable. This doubles the custom variable counts, but the segmentation by custom variable magically starts to work.

Why will it only work if I have added both a “page” entry and a “visit” entry for the same custom variable? I think it might have something to do with daveb’s post:

[quote=daveb]
Actions.getPageTitles is the report I am trying to segment. The code ends up back at ArchiveProcessing/Period.php which counts the number of visits that apply before generating the report and checks the Visit scoped custom variable, which of course does not exist.[/quote]

Any suggestions?

Thanks

Hi,

I fixed this by modifying the code that counts the number of visits to take into account page variables when counting the actions.

I will create a patch and submit a bug report. This looks like an oversight or just an unexplored code path. Actions.get definitely cannot return any results for page scope variables without my changes.

[quote=daveb]
Hi,

I fixed this by modifying the code that counts the number of visits to take into account page variables when counting the actions.

I will create a patch and submit a bug report. This looks like an oversight or just an unexplored code path. Actions.get definitely cannot return any results for page scope variables without my changes.[/quote]

Thanks daveb. I will be watching for your patch.

Matt,

Was this just an oversight or is there a reason that Actions.get cannot return results for page scope variables?

Was this just an oversight or is there a reason that Actions.get cannot return results for page scope variables?

Actions.get* should work on page scope variables of course, if it doesn’t then it is definitely a bug.

please create a ticket, and thank you in advance daveb for the patch!

Daveb has posted a fix for this issue:

http://dev.piwik.org/trac/ticket/2633

A big thanks to daveb for posting the fix!

Happy New Year! If you are still using Piwik and interested in the awesome new feature of “Creating a Custom Segment in Piwik and apply to reports in Real time!” we need YOUR help, with a little or big donation at: http://crowdfunding.piwik.org/custom-segments-editor/

This will allow to dynamically add or edit, a new set of rules for example “Show all visitors from USA and using Firefox and using Google”. This will be done via a simple to use interface. See screenshots and more info here: http://crowdfunding.piwik.org/custom-segments-editor/

We are crowd funding the future of Piwik and this feature in particular. With your help we can do it.

Thanks

Matthieu

Im having similar issues when trying to segment by custom Variables.

Im my tracking code I use id=1 for my custom variable with the name ‘Player’ and use various values to capture custom events. E.g.:


_paq.push(['setCustomVariable',1,'Player','event1','page']);
_paq.push(['trackPageView']);

The following url gives me a neat list of results back:


[myPiwik]?module=API&method=VisitsSummary.get&idSite=3&period=day&date=2014-03-25&expanded=1&format=xml&token_auth=[myToken]&segment=pageUrl==[myPageUrl]

However when I add


;customVariableName1==Player

to the url I get back only zeros:


<result>
<nb_uniq_visitors>0</nb_uniq_visitors>
<nb_visits>0</nb_visits>
<nb_actions>0</nb_actions>
<nb_visits_converted>0</nb_visits_converted>
<bounce_count>0</bounce_count>
<sum_visit_length>0</sum_visit_length>
<max_actions>0</max_actions>
<bounce_rate>0%</bounce_rate>
<nb_actions_per_visit>0</nb_actions_per_visit>
<avg_time_on_site>0</avg_time_on_site>
</result>

Im sure there are custom variables under the name ‘player’ with id=1 as I can request them using CustomVariables.getCustomVariablesValuesFromNameId(…)

When I try to use this segmentation it on a request URL that uses the method CustomVariables.getCustomVariablesValuesFromNameId(…) I just get a completely empty result:


<result/>

Am I missing something here?