Using multiple Visitor IP ranges in an API segment


#1

I am trying to segment my visitors based on IPs.

I know a group of visitors use a number of IP ranges and I am trying to create a Visitor IP segment based on the ranges. But instead of adding on to each added range, the segment is reducing with each range added.

How do I write it to make the ranges accumulate. So segment visits by IPs between “Range X” OR “Range Y” OR “Range Z”?

https://MYSITE/piwik/index.php
?token_auth=XXXXYYYYY
&format=xml
&date=2014-9-30
&period=month
&idSite=6
&module=API&method=VisitsSummary.getVisits
&segment=visitIp>=65.93.227.0;visitIp>=65.93.227.254,
visitIp>=65.93.228.0;visitIp>=65.93.228.254,
visitIp>=131.134.0.0;visitIp>=131.135.255.254,
visitIp>=131.136.0.0;visitIp>=131.139.255.254


(Matthieu Aubry) #2

In the doc: Segmentation: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 it says “Note that if you combine OR and AND operators, the OR operator will take precedence.”

Unfortunately because of this, I don’t know how you can select rangeA OR rangeB OR rangeC

Probably the best way maybe to add a new segment for IP range, but i’m not sure?


#3

hello,
if you need to define a segmentX: IP in rangeA OR rangeB OR rangeC
where:
rangeA --> A1<=visitIp<=A2
rangeB --> B1<=visitIp<=B2
rangeC --> C1<=visitIp<=C2

you can write in a single segment the following conditions:
visitIp>=A1
AND
visitIp<=A2 OR visitIp>=B1
AND
visitIp<=B2 OR visitIp>=C1
AND
visitIp<=C2

only IP in one of the three range will match the 4 condition AND.

An example to match only IP private addresses
&segment=visitIp>=10.0.0.0;visitIp<=10.255.255.255,visitIp>=172.16.0.0;visitIp<=172.31.255.255,visitIp>=192.168.0.0;visitIp<=192.168.255.255

ciao
ugo