Skip to content
Extraits de code Groupes Projets
Valider a6004773 rédigé par mattpiwik's avatar mattpiwik
Parcourir les fichiers

Refs #1736 - Segmentation doc now online: http://piwik.org/docs/analytics-api/segmentation/

 

git-svn-id: http://dev.piwik.org/svn/trunk@3878 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent 2a245720
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,9 +5,18 @@ class Piwik_Segment ...@@ -5,9 +5,18 @@ class Piwik_Segment
* @var Piwik_SegmentExpression * @var Piwik_SegmentExpression
*/ */
protected $segment = null; protected $segment = null;
/**
* Truncate the Segments to 4k
*/
const SEGMENT_TRUNCATE_LIMIT = 4096;
public function __construct($string, $idSites) public function __construct($string, $idSites)
{ {
$string = trim($string); $string = trim($string);
// As a preventive measure, we restrict the filter size to a safe limit
$string = substr($string, 0, self::SEGMENT_TRUNCATE_LIMIT);
$this->string = $string; $this->string = $string;
$this->idSites = $idSites; $this->idSites = $idSites;
$segment = new Piwik_SegmentExpression($string); $segment = new Piwik_SegmentExpression($string);
...@@ -46,7 +55,8 @@ class Piwik_Segment ...@@ -46,7 +55,8 @@ class Piwik_Segment
{ {
$expressions = $this->segment->parsedSubExpressions; $expressions = $this->segment->parsedSubExpressions;
$uniqueFields = array(); $uniqueFields = array();
foreach($expressions as $expression) { foreach($expressions as $expression)
{
$uniqueFields[] = $expression[Piwik_SegmentExpression::INDEX_OPERAND][0]; $uniqueFields[] = $expression[Piwik_SegmentExpression::INDEX_OPERAND][0];
} }
return $uniqueFields; return $uniqueFields;
......
...@@ -105,8 +105,9 @@ class Piwik_API_API ...@@ -105,8 +105,9 @@ class Piwik_API_API
'category' => 'Visit', 'category' => 'Visit',
'name' => 'General_VisitorIP', 'name' => 'General_VisitorIP',
'segment' => 'visitIp', 'segment' => 'visitIp',
'acceptedValues' => '13.54.122.1, etc.',
'sqlSegment' => 'location_ip', 'sqlSegment' => 'location_ip',
'sqlFilter' => array('Piwik_Common', 'long2ip'), 'sqlFilter' => array('Piwik_Common', 'getIp'),
'permission' => Piwik::isUserHasAdminAccess($idSites), 'permission' => Piwik::isUserHasAdminAccess($idSites),
); );
$segments[] = array( $segments[] = array(
...@@ -160,7 +161,7 @@ class Piwik_API_API ...@@ -160,7 +161,7 @@ class Piwik_API_API
$columns = array('type', 'category', 'name', 'segment'); $columns = array('type', 'category', 'name', 'segment');
foreach($columns as $column) foreach($columns as $column)
{ {
$compare = strcmp($row1[$column], $row2[$column]); $compare = -1 * strcmp($row1[$column], $row2[$column]);
if($compare != 0){ if($compare != 0){
return $compare; return $compare;
} }
......
...@@ -43,4 +43,73 @@ class Piwik_API_Controller extends Piwik_Controller ...@@ -43,4 +43,73 @@ class Piwik_API_Controller extends Piwik_Controller
$view->list_api_methods_with_links = $ApiDocumentation->getAllInterfaceString(); $view->list_api_methods_with_links = $ApiDocumentation->getAllInterfaceString();
echo $view->render(); echo $view->render();
} }
public function listSegments()
{
$segments = Piwik_API_API::getInstance()->getSegmentsMetadata($this->idSite);
$tableDimensions = $tableMetrics = '';
$customVariables=0;
$lastCategory=array();
foreach($segments as $segment)
{
$customVariableWillBeDisplayed = in_array($segment['segment'], $onlyDisplay = array('customVariableName1', 'customVariableName2', 'customVariableValue1', 'customVariableValue2'));
// Don't display more than 4 custom variables name/value rows
if($segment['category'] == 'Custom Variables'
&& !$customVariableWillBeDisplayed)
{
continue;
}
$thisCategory = $segment['category'];
$output = '';
if(empty($lastCategory[$segment['type']])
|| $lastCategory[$segment['type']] != $thisCategory)
{
$output .= '<tr><td colspan="2"><b>'.$thisCategory.'</b></td></tr>';
}
$lastCategory[$segment['type']] = $thisCategory;
$exampleValues = isset($segment['acceptedValues'])
? 'Example values: <code>'.$segment['acceptedValues'].'</code>'
: '';
$output .= '<tr>
<td>'.$segment['segment'].'</td>
<td>'.$segment['name'] .'<br/>'.$exampleValues.' </td>
</tr>';
// Show only 2 custom variables and display message for rest
if($customVariableWillBeDisplayed)
{
$customVariables++;
if($customVariables == 4)
{
$output .= '<tr><td> There are 5 custom variables available, so you can segment across any segment name and value range.
<br/>For example, <code>customVariableName1==Type;customVariableValue1==Customer</code>
<br/>Returns all visitors that have the Custom Variable "Type" set to "Customer".
</td></tr>';
}
}
if($segment['type'] == 'dimension') {
$tableDimensions .= $output;
} else {
$tableMetrics .= $output;
}
}
echo "
<b>Dimensions</b>
<table>
$tableDimensions
</table>
<br/>
<b>Metrics</b>
<table>
$tableMetrics
</table>
";
}
} }
...@@ -63,6 +63,7 @@ class Piwik_Provider extends Piwik_Plugin ...@@ -63,6 +63,7 @@ class Piwik_Provider extends Piwik_Plugin
'category' => 'Visit', 'category' => 'Visit',
'name' => Piwik_Translate('Provider_ColumnProvider'), 'name' => Piwik_Translate('Provider_ColumnProvider'),
'segment' => 'provider', 'segment' => 'provider',
'acceptedValues' => 'comcast.net, proxad.net, etc.',
'sqlSegment' => 'location_provider' 'sqlSegment' => 'location_provider'
); );
} }
......
...@@ -110,6 +110,7 @@ class Piwik_Referers extends Piwik_Plugin ...@@ -110,6 +110,7 @@ class Piwik_Referers extends Piwik_Plugin
'category' => 'Referers_Referers', 'category' => 'Referers_Referers',
'name' => 'Referers_ColumnKeyword', 'name' => 'Referers_ColumnKeyword',
'segment' => 'referrerKeyword', 'segment' => 'referrerKeyword',
'acceptedValues' => 'Encoded%20Keyword, keyword',
'sqlSegment' => 'referer_keyword', 'sqlSegment' => 'referer_keyword',
); );
$segments[] = array( $segments[] = array(
...@@ -117,12 +118,14 @@ class Piwik_Referers extends Piwik_Plugin ...@@ -117,12 +118,14 @@ class Piwik_Referers extends Piwik_Plugin
'category' => 'Referers_Referers', 'category' => 'Referers_Referers',
'name' => 'Referers_RefererName', 'name' => 'Referers_RefererName',
'segment' => 'referrerName', 'segment' => 'referrerName',
'acceptedValues' => 'twitter.com, www.facebook.com, Bing, Google, Yahoo, CampaignName',
'sqlSegment' => 'referer_name', 'sqlSegment' => 'referer_name',
); );
$segments[] = array( $segments[] = array(
'type' => 'dimension', 'type' => 'dimension',
'category' => 'Referers_Referers', 'category' => 'Referers_Referers',
'name' => 'Live_Referrer_URL', 'name' => 'Live_Referrer_URL',
'acceptedValues' => 'http%3A%2F%2Fwww.example.org%2Freferer-page.htm',
'segment' => 'referrerUrl', 'segment' => 'referrerUrl',
'sqlSegment' => 'referer_url', 'sqlSegment' => 'referer_url',
); );
......
...@@ -85,13 +85,14 @@ class Piwik_VisitTime extends Piwik_Plugin ...@@ -85,13 +85,14 @@ class Piwik_VisitTime extends Piwik_Plugin
public function getSegmentsMetadata($notification) public function getSegmentsMetadata($notification)
{ {
$segments =& $notification->getNotificationObject(); $segments =& $notification->getNotificationObject();
$acceptedValues = "0, 1, 2, 3, ..., 20, 21, 22, 23";
$segments[] = array( $segments[] = array(
'type' => 'dimension', 'type' => 'dimension',
'category' => 'Visit', 'category' => 'Visit',
'name' => Piwik_Translate('VisitTime_ColumnServerTime'), 'name' => Piwik_Translate('VisitTime_ColumnServerTime'),
'segment' => 'visitServerHour', 'segment' => 'visitServerHour',
'sqlSegment' => 'HOUR(visit_last_action_time)', 'sqlSegment' => 'HOUR(visit_last_action_time)',
'acceptedValues' => implode(',', range(0, 23, 1)) 'acceptedValues' => $acceptedValues
); );
$segments[] = array( $segments[] = array(
'type' => 'dimension', 'type' => 'dimension',
...@@ -99,7 +100,7 @@ class Piwik_VisitTime extends Piwik_Plugin ...@@ -99,7 +100,7 @@ class Piwik_VisitTime extends Piwik_Plugin
'name' => Piwik_Translate('VisitTime_ColumnLocalTime'), 'name' => Piwik_Translate('VisitTime_ColumnLocalTime'),
'segment' => 'visitLocalHour', 'segment' => 'visitLocalHour',
'sqlSegment' => 'HOUR(visitor_localtime)', 'sqlSegment' => 'HOUR(visitor_localtime)',
'acceptedValues' => implode(',', range(0, 23, 1)) 'acceptedValues' => $acceptedValues
); );
} }
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<result> <result>
<row> <row>
<type>dimension</type> <type>metric</type>
<category>Actions</category> <category>Visit</category>
<name>Entry Page URL</name> <name>Visit Duration (in seconds)</name>
<segment>entryPageUrl</segment> <segment>visitDuration</segment>
</row> </row>
<row> <row>
<type>dimension</type> <type>metric</type>
<category>Actions</category> <category>Visit</category>
<name>Entry Page title</name> <name>Number of Actions</name>
<segment>entryPageTitle</segment> <segment>actions</segment>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Actions</category> <category>Visit</category>
<name>Exit Page Title</name> <name>Visitor type</name>
<segment>exitPageTitle</segment> <segment>visitorType</segment>
<acceptedValues>new, returning</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Actions</category> <category>Visit</category>
<name>Exit Page URL</name> <name>Visitor IP</name>
<segment>exitPageUrl</segment> <segment>visitIp</segment>
<acceptedValues>13.54.122.1, etc.</acceptedValues>
<permission>1</permission>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable name 1</name> <name>Server time</name>
<segment>customVariableName1</segment> <segment>visitServerHour</segment>
<acceptedValues>0, 1, 2, 3, ..., 20, 21, 22, 23</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable name 2</name> <name>Resolution</name>
<segment>customVariableName2</segment> <segment>resolution</segment>
<acceptedValues>1280x1024, 800x600, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable name 3</name> <name>Provider</name>
<segment>customVariableName3</segment> <segment>provider</segment>
<acceptedValues>comcast.net, proxad.net, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable name 4</name> <name>Operating system</name>
<segment>customVariableName4</segment> <segment>operatingSystem</segment>
<acceptedValues>WXP, WI7, MAC, LIN, AND, IPD, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable name 5</name> <name>Local time</name>
<segment>customVariableName5</segment> <segment>visitLocalHour</segment>
<acceptedValues>0, 1, 2, 3, ..., 20, 21, 22, 23</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable value 1</name> <name>Country</name>
<segment>customVariableValue1</segment> <segment>country</segment>
<acceptedValues>de, us, fr, in, es, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable value 2</name> <name>Continent</name>
<segment>customVariableValue2</segment> <segment>continent</segment>
<acceptedValues>eur, asi, amc, amn, ams, afr, ant, oce</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable value 3</name> <name>Browser version</name>
<segment>customVariableValue3</segment> <segment>browserVersion</segment>
<acceptedValues>1.0, 8.0, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Visit</category>
<name>Custom Variable value 4</name> <name>Browser</name>
<segment>customVariableValue4</segment> <segment>browserName</segment>
<acceptedValues>FF, IE, CH, SF, OP, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Custom Variables</category> <category>Referrers</category>
<name>Custom Variable value 5</name> <name>Referrer URL</name>
<segment>customVariableValue5</segment> <acceptedValues>http%3A%2F%2Fwww.example.org%2Freferer-page.htm</acceptedValues>
<segment>referrerUrl</segment>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Referrers</category> <category>Referrers</category>
<name>Keyword</name> <name>Referrer Type</name>
<segment>referrerKeyword</segment> <segment>referrerType</segment>
<acceptedValues>direct, search, website, campaign</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Referrers</category> <category>Referrers</category>
<name>Referrer Name</name> <name>Referrer Name</name>
<segment>referrerName</segment> <segment>referrerName</segment>
<acceptedValues>twitter.com, www.facebook.com, Bing, Google, Yahoo, CampaignName</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Referrers</category> <category>Referrers</category>
<name>Referrer Type</name> <name>Keyword</name>
<segment>referrerType</segment> <segment>referrerKeyword</segment>
<acceptedValues>direct, search, website, campaign</acceptedValues> <acceptedValues>Encoded%20Keyword, keyword</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Referrers</category> <category>Custom Variables</category>
<name>Referrer URL</name> <name>Custom Variable value 5</name>
<segment>referrerUrl</segment> <segment>customVariableValue5</segment>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Browser</name> <name>Custom Variable value 4</name>
<segment>browserName</segment> <segment>customVariableValue4</segment>
<acceptedValues>FF, IE, CH, SF, OP, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Browser version</name> <name>Custom Variable value 3</name>
<segment>browserVersion</segment> <segment>customVariableValue3</segment>
<acceptedValues>1.0, 8.0, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Continent</name> <name>Custom Variable value 2</name>
<segment>continent</segment> <segment>customVariableValue2</segment>
<acceptedValues>eur, asi, amc, amn, ams, afr, ant, oce</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Country</name> <name>Custom Variable value 1</name>
<segment>country</segment> <segment>customVariableValue1</segment>
<acceptedValues>de, us, fr, in, es, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Local time</name> <name>Custom Variable name 5</name>
<segment>visitLocalHour</segment> <segment>customVariableName5</segment>
<acceptedValues>0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Operating system</name> <name>Custom Variable name 4</name>
<segment>operatingSystem</segment> <segment>customVariableName4</segment>
<acceptedValues>WXP, WI7, MAC, LIN, AND, IPD, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Provider</name> <name>Custom Variable name 3</name>
<segment>provider</segment> <segment>customVariableName3</segment>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Resolution</name> <name>Custom Variable name 2</name>
<segment>resolution</segment> <segment>customVariableName2</segment>
<acceptedValues>1280x1024, 800x600, etc.</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Custom Variables</category>
<name>Server time</name> <name>Custom Variable name 1</name>
<segment>visitServerHour</segment> <segment>customVariableName1</segment>
<acceptedValues>0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23</acceptedValues>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Actions</category>
<name>Visitor IP</name> <name>Exit Page URL</name>
<segment>visitIp</segment> <segment>exitPageUrl</segment>
<permission>1</permission>
</row> </row>
<row> <row>
<type>dimension</type> <type>dimension</type>
<category>Visit</category> <category>Actions</category>
<name>Visitor type</name> <name>Exit Page Title</name>
<segment>visitorType</segment> <segment>exitPageTitle</segment>
<acceptedValues>new, returning</acceptedValues>
</row> </row>
<row> <row>
<type>metric</type> <type>dimension</type>
<category>Visit</category> <category>Actions</category>
<name>Number of Actions</name> <name>Entry Page title</name>
<segment>actions</segment> <segment>entryPageTitle</segment>
</row> </row>
<row> <row>
<type>metric</type> <type>dimension</type>
<category>Visit</category> <category>Actions</category>
<name>Visit Duration (in seconds)</name> <name>Entry Page URL</name>
<segment>visitDuration</segment> <segment>entryPageUrl</segment>
</row> </row>
</result> </result>
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter