Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New "Event URL" segment eventUrl to segment on any Segment URL #12236

Merged
merged 10 commits into from Dec 1, 2017
3 changes: 2 additions & 1 deletion core/Tracker/TableLogAction.php
Expand Up @@ -180,7 +180,7 @@ public static function getIdActionFromSegment($valueToMatch, $sqlField, $matchTy
$sql = 'SELECT idaction FROM ' . Common::prefixTable('log_action') . ' WHERE type = ' . $actionType . ' )';
} else {
$actionType = self::guessActionTypeFromSegment($segmentName);
if ($actionType == Action::TYPE_PAGE_URL) {
if ($actionType == Action::TYPE_PAGE_URL || $segmentName == 'eventUrl') {
// for urls trim protocol and www because it is not recorded in the db
$valueToMatch = preg_replace('@^http[s]?://(www\.)?@i', '', $valueToMatch);
}
Expand Down Expand Up @@ -217,6 +217,7 @@ private static function guessActionTypeFromSegment($segmentName)
$exactMatch = array(
'outlinkUrl' => Action::TYPE_OUTLINK,
'downloadUrl' => Action::TYPE_DOWNLOAD,
'eventUrl' => Action::TYPE_EVENT,
'eventAction' => Action::TYPE_EVENT_ACTION,
'eventCategory' => Action::TYPE_EVENT_CATEGORY,
'eventName' => Action::TYPE_EVENT_NAME,
Expand Down
2 changes: 1 addition & 1 deletion plugins/API/API.php
Expand Up @@ -666,7 +666,7 @@ protected function doesSegmentNeedActionsData($segmentName)
$segmentsNeedActionsInfo = array('visitConvertedGoalId',
'pageUrl', 'pageTitle', 'siteSearchKeyword',
'entryPageTitle', 'entryPageUrl', 'exitPageTitle', 'exitPageUrl',
'outlinkUrl', 'downloadUrl'
'outlinkUrl', 'downloadUrl', 'eventUrl'
);
$isCustomVariablePage = stripos($segmentName, 'customVariablePage') !== false;
$isEventSegment = stripos($segmentName, 'event') !== false;
Expand Down
2 changes: 1 addition & 1 deletion plugins/Actions/Columns/ActionUrl.php
Expand Up @@ -21,7 +21,7 @@ protected function configureSegments()
$segment = new Segment();
$segment->setSegment('actionUrl');
$segment->setName('Actions_ColumnActionURL');
$segment->setUnionOfSegments(array('pageUrl', 'downloadUrl', 'outlinkUrl'));
$segment->setUnionOfSegments(array('pageUrl', 'downloadUrl', 'outlinkUrl', 'eventUrl'));

$this->addSegment($segment);
}
Expand Down
38 changes: 38 additions & 0 deletions plugins/Events/Columns/EventUrl.php
@@ -0,0 +1,38 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Events\Columns;

use Piwik\Columns\Discriminator;
use Piwik\Columns\Join\ActionNameJoin;
use Piwik\Plugin\Dimension\ActionDimension;
use Piwik\Tracker\Action;

class EventUrl extends ActionDimension
{
protected $columnName = 'idaction_url';
protected $segmentName = 'eventUrl';
protected $nameSingular = 'Events_EventUrl';
protected $namePlural = 'Events_EventUrls';
protected $type = self::TYPE_URL;
protected $acceptValues = 'The URL must be URL encoded, for example: http%3A%2F%2Fexample.com%2Fpath%2Fpage%3Fquery';
protected $category = 'Events_Events';
protected $sqlFilter = '\\Piwik\\Tracker\\TableLogAction::getIdActionFromSegment';

public function getDbColumnJoin()
{
return new ActionNameJoin();
}

public function getDbDiscriminator()
{
return new Discriminator('log_action', 'type', Action::TYPE_EVENT);
}

}

2 changes: 2 additions & 0 deletions plugins/Events/lang/en.json
Expand Up @@ -11,6 +11,8 @@
"EventCategory": "Event Category",
"EventName": "Event Name",
"EventNames": "Event Names",
"EventUrl": "Event URL",
"EventUrls": "Event URLs",
"Events": "Events",
"EventsWithValue": "Events with a value",
"EventsWithValueDocumentation": "Number of events where an Event value was set",
Expand Down
1 change: 1 addition & 0 deletions plugins/Live/Visitor.php
Expand Up @@ -221,6 +221,7 @@ public static function flattenVisitorDetailsArray($visitorDetailsArray)
$flattenForActionType = array(
'outlink' => 'outlinkUrl',
'download' => 'downloadUrl',
'event' => 'eventUrl',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was needed to get suggested values for this segment

'action' => 'pageUrl'
);
foreach($flattenForActionType as $actionType => $flattenedKeyPrefix) {
Expand Down
5 changes: 3 additions & 2 deletions tests/PHPUnit/Integration/SegmentTest.php
Expand Up @@ -832,9 +832,10 @@ public function test_getSelectQuery_whenUnionOfSegmentsAreUsed()
ON log_link_visit_action.idvisit = log_visit.idvisit
WHERE (( log_link_visit_action.idaction_url IN (SELECT idaction FROM log_action WHERE ( name LIKE CONCAT('%', ?, '%') AND type = 1 )) )
OR ( log_link_visit_action.idaction_url IN (SELECT idaction FROM log_action WHERE ( name LIKE CONCAT('%', ?, '%') AND type = 3 )) )
OR ( log_link_visit_action.idaction_url IN (SELECT idaction FROM log_action WHERE ( name LIKE CONCAT('%', ?, '%') AND type = 2 )) ) )
OR ( log_link_visit_action.idaction_url IN (SELECT idaction FROM log_action WHERE ( name LIKE CONCAT('%', ?, '%') AND type = 2 )) )
OR ( log_link_visit_action.idaction_url IN (SELECT idaction FROM log_action WHERE ( name LIKE CONCAT('%', ?, '%') AND type = 10 )) ) )
GROUP BY log_visit.idvisit ORDER BY NULL ) AS log_inner",
"bind" => array('myTestUrl', 'myTestUrl', 'myTestUrl'));
"bind" => array('myTestUrl', 'myTestUrl', 'myTestUrl', 'myTestUrl'));

$this->assertEquals($this->removeExtraWhiteSpaces($expected), $this->removeExtraWhiteSpaces($query));
}
Expand Down
@@ -1,23 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<row>http://piwik.net/grue/lair</row>
<row>http://piwik.net/space/quest/iv</row>
<row>http://example-outlink.org/1.html</row>
<row>http://piwik.net/grue/lair</row>
<row>http://example.org/path/file1.zip</row>
<row>http://example.org/path/file0.zip</row>
<row>http://example-outlink.org/1.html</row>
<row>http://example-outlink.org/0.html</row>
<row>http://example.org/path/file2.zip</row>
<row>http://example.org/path/file3.zip</row>
<row>http://example-outlink.org/3.html</row>
<row>http://example.org/path/file3.zip</row>
<row>http://example-outlink.org/2.html</row>
<row>http://example.org/path/file2.zip</row>
<row>http://example-outlink.org/7.html</row>
<row>http://example-outlink.org/8.html</row>
<row>http://example.org/path/file4.zip</row>
<row>http://example.org/path/file5.zip</row>
<row>http://example.org/path/file8.zip</row>
<row>http://example-outlink.org/6.html</row>
<row>http://example-outlink.org/7.html</row>
<row>http://example-outlink.org/5.html</row>
<row>http://example.org/path/file6.zip</row>
<row>http://example-outlink.org/4.html</row>
<row>http://example-outlink.org/5.html</row>
<row>http://example.org/path/file8.zip</row>
<row>http://example.org/path/file7.zip</row>
<row>http://example-outlink.org/8.html</row>
<row>http://example.org/path/file6.zip</row>
<row>http://example.org/path/file5.zip</row>
</result>
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<nb_visits>18</nb_visits>
<nb_actions>18</nb_actions>
<nb_visits_converted>18</nb_visits_converted>
<bounce_count>18</bounce_count>
<sum_visit_length>0</sum_visit_length>
<max_actions>1</max_actions>
<bounce_rate>100%</bounce_rate>
<nb_actions_per_visit>1</nb_actions_per_visit>
<avg_time_on_site>0</avg_time_on_site>
<nb_visits>17</nb_visits>
<nb_actions>77</nb_actions>
<nb_visits_converted>17</nb_visits_converted>
<bounce_count>0</bounce_count>
<sum_visit_length>27557</sum_visit_length>
<max_actions>5</max_actions>
<bounce_rate>0%</bounce_rate>
<nb_actions_per_visit>4.5</nb_actions_per_visit>
<avg_time_on_site>1621</avg_time_on_site>
</result>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<row>http://piwik.net/space/quest/iv</row>
</result>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<result>
<nb_visits>17</nb_visits>
<nb_actions>77</nb_actions>
<nb_visits_converted>17</nb_visits_converted>
<bounce_count>0</bounce_count>
<sum_visit_length>27557</sum_visit_length>
<max_actions>5</max_actions>
<bounce_rate>0%</bounce_rate>
<nb_actions_per_visit>4.5</nb_actions_per_visit>
<avg_time_on_site>1621</avg_time_on_site>
</result>
Expand Up @@ -460,6 +460,7 @@
<row>pageUrl</row>
<row>downloadUrl</row>
<row>outlinkUrl</row>
<row>eventUrl</row>
</unionOfSegments>
</row>
<row>
Expand Down Expand Up @@ -576,6 +577,13 @@
<name>Event Name</name>
<segment>eventName</segment>
</row>
<row>
<type>dimension</type>
<category>Events</category>
<name>Event URL</name>
<segment>eventUrl</segment>
<acceptedValues>The URL must be URL encoded, for example: http%3A%2F%2Fexample.com%2Fpath%2Fpage%3Fquery</acceptedValues>
</row>
<row>
<type>dimension</type>
<category>Referrers</category>
Expand Down