protected function trackVisits() { $dateTime = $this->dateTime; $idSite = $this->idSite; $idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit; $idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit; $t = $this->getTracker($idSite, $dateTime, $defaultInit = true); // Record 1st goal, should only have 1 conversion $t->setUrl('http://example.org/index.htm'); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); $this->checkResponse($t->doTrackPageView('Thank you mate')); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); $this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000)); // Record 2nd goal, should record both conversions $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.5)->getDatetime()); $this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300)); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.6)->getDatetime()); $this->checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366)); // Update & set to not allow multiple $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); $goal = $goals[$idGoal_OneConversionPerVisit]; $this->assertTrue($goal['allow_multiple'] == 0); Piwik_Goals_API::getInstance()->updateGoal($idSite, $idGoal_OneConversionPerVisit, $goal['name'], @$goal['match_attribute'], @$goal['pattern'], @$goal['pattern_type'], @$goal['case_sensitive'], $goal['revenue'], $goal['allow_multiple'] = 1); $this->assertTrue($goal['allow_multiple'] == 1); // 1st goal should Now be tracked $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.61)->getDatetime()); $this->checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656)); }
public function setColumnsToDisplay($columnsNames) { $newColumnsNames = array(); $goals = array(); $idSite = $this->getIdSite(); if ($idSite) { $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); } foreach ($columnsNames as $columnName) { if (in_array($columnName, array('goal_%s_conversion_rate', 'goal_%s_nb_conversions', 'goal_%s_revenue_per_visit'))) { foreach ($goals as $goal) { $idgoal = $goal['idgoal']; if ($this->processOnlyIdGoal > Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE && $this->processOnlyIdGoal != $idgoal) { continue; } $name = Piwik_Translate($this->getColumnTranslation($columnName), $goal['name']); $columnNameGoal = str_replace('%s', $idgoal, $columnName); $this->setColumnTranslation($columnNameGoal, $name); if (strstr($columnNameGoal, '_rate') === false && $this->processOnlyIdGoal == Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW) { continue; } if (strstr($columnNameGoal, '_revenue') !== false) { $this->columnsToRevenueFilter[] = $columnNameGoal; } else { $this->columnsToConversionFilter[] = $columnNameGoal; } $newColumnsNames[] = $columnNameGoal; } } else { $newColumnsNames[] = $columnName; } } parent::setColumnsToDisplay($newColumnsNames); }
protected static function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC self::createWebsite(self::$dateTime); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js', 'manually', '', ''); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'second goal', 'manually', '', ''); }
public function setUp() { parent::setUp(); $this->idSite = $this->createWebsite($this->dateTime); // for conversion testing $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); }
protected static function trackVisits() { // tests run in UTC, the Tracker in UTC $dateTime = self::$dateTime; $idSite = self::$idSite; $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1); // Also testing to record this as a bot while specifically allowing bots $t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); $t->DEBUG_APPEND_URL .= '&bots=1'; $t->DEBUG_APPEND_URL .= '&forceIpAnonymization=1'; // VISIT 1 = Referrer is "Keyword not defined" // Alsotrigger goal to check that attribution goes to this keyword $t->setUrlReferrer('http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC&url=http%3A%2F%2Fpiwik.org%2F&ei=&usg='); $t->setUrl('http://example.org/this%20is%20cool!'); self::checkResponse($t->doTrackPageView('incredible title!')); $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); self::checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); // VISIT 2 = Referrer has keyword, but the URL should be rewritten // in Live Output to point to google search result page $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime()); $t->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja'); // Test with empty title, that the output of Live is valid self::checkResponse($t->doTrackPageView('')); }
function fetchGoalsFromDb($notification) { $idsite = $notification->getNotificationInfo(); // add the 'goal' entry in the website array $array =& $notification->getNotificationObject(); $array['goals'] = Piwik_Goals_API::getInstance()->getGoals($idsite); }
public function setUp() { // add one site $this->idSite = $this->createWebsite($this->dateTime, 1, "Site #0"); // add two goals $goals = Piwik_Goals_API::getInstance(); $this->idGoal1 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); $this->idGoal2 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains'); $urls = array(); for ($i = 0; $i != 2; ++$i) { $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $title = "page view " . ($i - 1) . " / " . ($i + 1); $urls[$url] = $title; } $visitTimes = array(); $date = Piwik_Date::factory($this->dateTime); for ($i = 0; $i != 250; ++$i) { // spread visits out through entire year $day = floor(365 * $i / 250); for ($j = 0; $j != 2; ++$j) { $visitTimes[] = $date->addDay($day)->addHour($j)->toString(); } } // add 12,000 page views (2 visits of 2 page views for 12 visitors on 250 days spread out through year) for ($visitor = 0; $visitor != 12; ++$visitor) { $t = $this->getTracker($this->idSite, $this->dateTime); foreach ($visitTimes as $visitTime) { $t->setForceVisitDateTime($visitTime); foreach ($urls as $url => $title) { $t->setUrl($url); $t->doTrackPageView($title); } } } }
protected static function setUpWebsitesAndGoals() { self::createWebsite(self::$dateTime, $ecommerce = 1); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'triggered js', 'manually', '', ''); }
public function setUp() { // add one site $this->idSite = $this->createWebsite($this->dateTime, 1, "Site #0"); // add two goals $goals = Piwik_Goals_API::getInstance(); $this->idGoal1 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); $this->idGoal2 = $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains'); $urls = array(); for ($i = 0; $i != 10; ++$i) { $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $title = "page view " . ($i - 1) . " / " . ($i + 1); $urls[$url] = $title; } $visitTimes = array(); $date = Piwik_Date::factory($this->dateTime); for ($i = 0; $i != 12; ++$i) { $visitTimes[] = $date->addHour($i)->toString(); } // add 10,000 page views (10 visits of 10 page views for 100 visitors) for ($visitor = 0; $visitor != 100; ++$visitor) { $t = $this->getTracker($this->idSite, $this->dateTime, $defaultInit = true); foreach ($visitTimes as $visitTime) { $t->setForceVisitDateTime($visitTime); foreach ($urls as $url => $title) { $t->setUrl($url); $t->doTrackPageView($title); } } } }
public function setUp() { parent::setUp(); $this->idSite = $this->createWebsite($this->dateTime, $ecommerce = 1); $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1); $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0); $this->idGoal3 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); }
public function setUp() { parent::setUp(); // tests run in UTC, the Tracker in UTC $this->idSite = $this->createWebsite($this->dateTime); $this->idGoal1 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', ''); $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'second goal', 'manually', '', ''); }
public function setUp() { parent::setUp(); $this->dateTime = '2011-04-05 00:11:42'; $this->idSite = $this->createWebsite($this->dateTime, $ecommerce = 1); $this->idSite2 = $this->createWebsite($this->dateTime); $this->idGoalStandard = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true); }
protected function trackVisitsImpl($t) { $dateTime = $this->dateTime; $idSite = $this->idSite; $t->disableCookieSupport(); $t->setUrlReferrer('http://referer.com/page.htm?param=valuewith some spaces'); // testing URL excluded parameters $parameterToExclude = 'excluded_parameter'; Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new name', $url = array('http://site.com'), $ecommerce = 0, $excludedIps = null, $parameterToExclude . ',anotherParameter'); // Record 1st page view $urlPage1 = 'http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY¶meter=Should display'; $t->setUrl($urlPage1); $this->checkResponse($t->doTrackPageView('incredible title!')); // testing that / and index.htm above record with different URLs // Recording the 2nd page after 3 minutes $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.05)->getDatetime()); $urlPage2 = 'http://example.org/'; $t->setUrl($urlPage2); // $t->setUrlReferrer($urlPage1); $this->checkResponse($t->doTrackPageView('Second page view - should be registered as URL /')); // $t->setUrlReferrer($urlPage2); // Click on external link after 6 minutes (3rd action) $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); $this->checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link')); // Click on file download after 12 minutes (4th action) $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime()); $this->checkResponse($t->doTrackAction('http://piwik.org/path/again/latest.zip', 'download')); // Create Goal 1: Triggered by JS, after 18 minutes $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', ''); $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.3)->getDatetime()); // Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country) $t->setBrowserLanguage('th'); $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); // Track same Goal twice (after 24 minutes), should only be tracked once $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.4)->getDatetime()); $this->checkResponse($t->doTrackGoal($idGoal, $revenue = 42)); $t->setBrowserLanguage('fr'); // Final page view (after 27 min) $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.45)->getDatetime()); $t->setUrl('http://example.org/index.htm'); $this->checkResponse($t->doTrackPageView('Looking at homepage (again)...')); // - // End of first visit: 24min // Create Goal 2: Matching on URL Piwik_Goals_API::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\\/purchase\\.(.*)', 'regex', false, $revenue = 1); // - // Start of returning visit, 1 hour after first page view $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); $t->setUrl('http://example.org/store/purchase.htm'); $t->setUrlReferrer('http://search.yahoo.com/search?p=purchase'); // Temporary, until we implement 1st party cookies in PiwikTracker $t->DEBUG_APPEND_URL = '&_idvc=2'; // Goal Tracking URL matching, testing custom referer including keyword $this->checkResponse($t->doTrackPageView('Checkout/Purchasing...')); // - // End of second visit }
function addNewExperiment() { $view = Piwik_View::factory('add_new_experiment'); $this->setGeneralVariablesView($view); $view->userCanEditExperiments = Piwik::isUserHasAdminAccess($this->idSite); $view->goalsPluginDeactived = !Piwik_PluginsManager::getInstance()->isPluginActivated('Goals'); $view->goals = Piwik_Goals_API::getInstance()->getGoals($this->idSite); $view->onlyShowAddNewExperiment = true; echo $view->render(); }
protected static function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC $ecommerce = self::$allowConversions ? 1 : 0; self::createWebsite(self::$dateTime, $ecommerce, "Site 1"); self::createWebsite(self::$dateTime, 0, "Site 2"); if (self::$allowConversions) { Piwik_Goals_API::getInstance()->addGoal(self::$idSite1, 'all', 'url', 'http', 'contains', false, 5); Piwik_Goals_API::getInstance()->addGoal(self::$idSite2, 'all', 'url', 'http', 'contains'); } }
public function getGoalsWithoutFunnels($idSite) { $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); $funnelsByGoal = $this->getFunnelsByGoal($idSite); $goalsWithoutFunnels = array(); foreach ($goals as &$goal) { if (!array_key_exists($goal['idgoal'], $funnelsByGoal)) { $goalsWithoutFunnels[$goal['idgoal']] = $goal; } } return $goalsWithoutFunnels; }
function addMenus() { $idSite = Piwik_Common::getRequestVar('idSite'); $experiments = Piwik_ABTests_API::getInstance()->getExperiments($idSite); $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); if (count($experiments) == 0 && count($goals) > 0) { Piwik_AddMenu(Piwik_Translate('ABTests_ABTests'), Piwik_Translate('ABTests_CreateExperiment'), array('module' => 'ABTests', 'action' => 'addNewExperiment')); } elseif (count($experiments) == 0) { # messge saying you need goals to create experiments } else { Piwik_AddMenu('ABTests_ABTests', 'ABTests_Overview', array('module' => 'ABTests')); foreach ($experiments as $experiment) { Piwik_AddMenu('ABTests_ABTests', str_replace('%', '%%', $experiment['name']), array('module' => 'ABTests', 'action' => 'experimentReport', 'idExperiment' => $experiment['idexperiment'])); } } }
public function setUp() { $sitesManager = Piwik_SitesManager_API::getInstance(); $goals = Piwik_Goals_API::getInstance(); // add one thousand sites $allIdSites = array(); for ($i = 0; $i < 1000; ++$i) { $allIdSites[] = IntegrationTestCase::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #{$i}"); } // add goals to 500 sites $idGoals = array(); foreach ($allIdSites as $idSite) { if ($idSite % 2 == 0) { $idGoal1 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5); $idGoal2 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains'); $idGoals[$idSite] = array($idGoal1, $idGoal2); } else { $idGoals[$idSite] = array(); } } $urls = array(); for ($i = 0; $i != 3; ++$i) { $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $title = "page view " . ($i - 1) . " / " . ($i + 1); $urls[$url] = $title; } $visitTimes = array(); $date = Piwik_Date::factory($this->date); for ($i = 0; $i != 4; ++$i) { $visitTimes[] = $date->addHour($i)->getDatetime(); } // add 12000 visits (3 visitors with 4 visits each for each site) w/ 3 pageviews each on one day foreach ($visitTimes as $visitTime) { foreach ($allIdSites as $idSite) { for ($visitor = 0; $visitor != 3; ++$visitor) { $t = BenchmarkTestCase::getLocalTracker($this->idSite); $ip = "157.5.6." . ($visitor + 1); $t->setIp($ip); $t->setForceVisitDateTime($visitTime); foreach ($urls as $url => $title) { $t->setUrl($url); $t->doTrackPageView($title); } } } } }
public function setUp() { $this->idSite = $this->createWebsite($this->dateTime, 1, "Site #0"); // add one goal $this->idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains'); for ($i = 0; $i != 10; ++$i) { $this->urls[] = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $this->titles[] = "page view " . ($i - 1) . " / " . ($i + 1); } $this->tracker = $this->getTracker($this->idSite, $this->dateTime); $date = Piwik_Date::factory($this->dateTime); for ($i = 0; $i != 10; ++$i) { for ($j = 0; $j != 10; ++$j) { $this->visitDates[] = $date->addDay($i)->addHour($j)->toString(); } } }
public function setColumnsToDisplay($columnsNames) { $newColumnsNames = array(); $goals = array(); $idSite = $this->getIdSite(); if ($idSite) { $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); $ecommerceGoal = array('idgoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER, 'name' => Piwik_Translate('Goals_EcommerceOrder')); $site = new Piwik_Site($idSite); //Case Ecommerce report table if ($this->isEcommerce) { $goals = array($ecommerceGoal); } elseif ($site->isEcommerceEnabled()) { $goals = array_merge(array($ecommerceGoal), $goals); } } foreach ($columnsNames as $columnName) { if (in_array($columnName, array('goal_%s_conversion_rate', 'goal_%s_nb_conversions', 'goal_%s_revenue_per_visit', 'goal_%s_revenue', 'goal_%s_avg_order_revenue', 'goal_%s_items'))) { foreach ($goals as $goal) { $idgoal = $goal['idgoal']; // Columns names are escaped in smarty via | escape:'html' $goal['name'] = Piwik_Common::unsanitizeInputValue($goal['name']); if ($this->processOnlyIdGoal > Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE && $this->processOnlyIdGoal != $idgoal && !$this->isEcommerce) { continue; } $name = Piwik_Translate($this->getColumnTranslation($columnName), $goal['name']); $columnNameGoal = str_replace('%s', $idgoal, $columnName); $this->setColumnTranslation($columnNameGoal, $name); $this->setDynamicMetricDocumentation($columnName, $columnNameGoal, $goal['name'], $goal['idgoal']); if (strpos($columnNameGoal, '_rate') === false && $this->processOnlyIdGoal == Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW) { continue; } if (strstr($columnNameGoal, '_revenue') !== false) { $this->columnsToRevenueFilter[] = $columnNameGoal; } else { $this->columnsToConversionFilter[] = $columnNameGoal; } $newColumnsNames[] = $columnNameGoal; } } else { $newColumnsNames[] = $columnName; } } parent::setColumnsToDisplay($newColumnsNames); }
public function test_addFunnel() { $idSite = Piwik_SitesManager_API::getInstance()->addSite("test site", "http://www.example.com"); $idGoal = Piwik_Goals_API::getInstance()->addGoal($idSite, "test goal", 'url', 'test', 'contains', 0, 0); $steps = array(1 => array('name' => 'step one', 'url' => 'http://www.example.com/step_one', 'id' => 1)); $idFunnel = Piwik_Funnels_API::getInstance()->addFunnel($idSite, $idGoal, $steps); $this->assertIsA($idFunnel, 'int'); $funnels = Piwik_Funnels_API::getInstance()->getFunnels($idSite); $this->assertTrue(count($funnels) === 1); $funnel = $funnels[$idFunnel]; $this->assertEqual($funnel['idsite'], $idSite); $this->assertEqual($funnel['idgoal'], $idGoal); $steps = $funnel['steps']; $this->assertTrue(count($steps) === 1); $step = $steps[0]; $this->assertEqual($step['name'], 'step one'); $this->assertEqual($step['url'], 'http://www.example.com/step_one'); $this->assertEqual($step['idstep'], 1); }
public function setUp() { // add one thousand sites for ($i = 0; $i < 1000; ++$i) { $this->idSites[] = $this->createWebsite($this->dateTime, 1, "Site #{$i}"); } // add goals to 500 sites $goals = Piwik_Goals_API::getInstance(); foreach ($this->idSites as $idSite) { if ($idSite % 2 == 0) { $idGoal1 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5); $idGoal2 = $goals->addGoal($idSite, 'all', 'url', 'http', 'contains'); $idGoals[$idSite] = array($idGoal1, $idGoal2); } else { $this->idGoals[$idSite] = array(); } } $urls = array(); for ($i = 0; $i != 2; ++$i) { $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $title = "page view " . ($i - 1) . " / " . ($i + 1); $urls[$url] = $title; } $visitTimes = array(); $date = Piwik_Date::factory($this->dateTime); for ($i = 0; $i != 2; ++$i) { $visitTimes[] = $date->addHour($i)->toString(); } // add 12 page views per site (2 visit w/ 2 page views for 3 visitors) foreach ($this->idSites as $idSite) { for ($visitor = 0; $visitor != 3; ++$visitor) { $t = $this->getTracker($idSite, $this->dateTime); foreach ($visitTimes as $visitTime) { $t->setForceVisitDateTime($visitTime); foreach ($urls as $url => $title) { $t->setUrl($url); $t->doTrackPageView($title); } } } } }
public function setColumnsToDisplay($columnsNames) { $newColumnsNames = array(); foreach ($columnsNames as $columnName) { if ($columnName == 'goal_%s_conversion_rate') { $goals = Piwik_Goals_API::getInstance()->getGoals($this->getIdSite()); foreach ($goals as $goal) { $idgoal = $goal['idgoal']; $name = $goal['name']; $columnName = 'goal_' . $idgoal . '_conversion_rate'; $newColumnsNames[] = $columnName; $this->setColumnTranslation($columnName, $name); $this->columnsToPercentageFilter[] = $columnName; } } else { $newColumnsNames[] = $columnName; } } parent::setColumnsToDisplay($newColumnsNames); }
public function setUp() { // add one site IntegrationTestCase::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/"); // add two goals $goals = Piwik_Goals_API::getInstance(); $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains'); $urls = array(); for ($i = 0; $i != 3; ++$i) { $url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1); $title = "page view " . ($i - 1) . " / " . ($i + 1); $urls[$url] = $title; } $visitTimes = array(); $date = Piwik_Date::factory($this->date); for ($month = 0; $month != 12; ++$month) { for ($day = 0; $day != 25; ++$day) { $hour = $time * 31 / 60.0; $visitTimes[] = $date->addPeriod($month, 'MONTH')->addDay($day)->getDatetime(); } } // add 12,000 visits (1 visit a day from 40 visitors for 25 days of every month) w/ 3 pageviews each foreach ($visitTimes as $visitTime) { for ($visitor = 0; $visitor != 40; ++$visitor) { $t = BenchmarkTestCase::getLocalTracker($this->idSite); $ip = "157.5.6." . ($visitor + 1); $t->setIp($ip); $t->setForceVisitDateTime($visitTime); foreach ($urls as $url => $title) { $t->setUrl($url); $t->doTrackPageView($title); } } } }
private function addLogData() { // tracks visits on the following days: // - 2012-01-09 // - 2012-01-14 // - 2012-01-19 // - 2012-01-24 <--- everything before this date is to be purged // - 2012-01-29 // - 2012-02-03 // - 2012-02-08 // - 2012-02-13 // - 2012-02-18 // - 2012-02-23 // - 2012-02-28 // 6 visits in feb, 5 in jan // following actions are created: // - 'First page view' // - 'Second page view' // - 'SKU2' // - 'Canon SLR' // - 'Electronics & Cameras' // - for every visit (11 visits total): // - http://whatever.com/_{$daysSinceLastVisit} // - http://whatever.com/42/{$daysSinceLastVisit} $start = $this->dateTime; $this->idSite = $this->createWebsite('2012-01-01', $ecommerce = 1); $idGoal = Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'match all', 'url', 'http', 'contains'); for ($daysAgo = $this->daysAgoStart; $daysAgo >= 0; $daysAgo -= 5) { $dateTime = $start->subDay($daysAgo)->toString(); $t = $this->getTracker($this->idSite, $dateTime, $defaultInit = true); $t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)'); // use $daysAgo to make sure new actions are created for every day and aren't used again. // when deleting visits, some of these actions will no longer be referenced in the DB. $t->setUrl("http://whatever.com/_{$daysAgo}"); $t->doTrackPageView('First page view'); $t->setUrl("http://whatever.com/42/{$daysAgo}"); $t->doTrackPageView('Second page view'); $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR', $category = 'Electronics & Cameras', $price = 1500, $quantity = 1); $t->doTrackEcommerceOrder($orderId = '937nsjusu ' . $dateTime, $grandTotal = 1111.11, $subTotal = 1000, $tax = 111, $shipping = 0.11, $discount = 666); } }
function __construct() { parent::__construct(); $this->idSite = Piwik_Common::getRequestVar('idSite'); $this->goals = Piwik_Goals_API::getInstance()->getGoals($this->idSite); }
public static function setUpWebsitesAndGoals() { self::createWebsite(self::$dateTime, $ecommerce = 1); self::createWebsite(self::$dateTime); Piwik_Goals_API::getInstance()->addGoal(self::$idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true); }
function addMenus() { $idSite = Piwik_Common::getRequestVar('idSite', null, 'int'); $goals = Piwik_Goals_API::getInstance()->getGoals($idSite); $mainGoalMenu = $this->getGoalCategoryName($idSite); $site = new Piwik_Site($idSite); if (count($goals) == 0) { Piwik_AddMenu($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal', 'idGoal' => $site->isEcommerceEnabled() ? Piwik_Archive::LABEL_ECOMMERCE_ORDER : null), true, 25); if ($site->isEcommerceEnabled()) { Piwik_AddMenu($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER), true, 1); } Piwik_AddMenu($mainGoalMenu, 'Goals_AddNewGoal', array('module' => 'Goals', 'action' => 'addNewGoal')); } else { Piwik_AddMenu($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index', 'idGoal' => $site->isEcommerceEnabled() ? Piwik_Archive::LABEL_ECOMMERCE_ORDER : null), true, 25); if ($site->isEcommerceEnabled()) { Piwik_AddMenu($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik_Archive::LABEL_ECOMMERCE_ORDER), true, 1); } Piwik_AddMenu($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2); foreach ($goals as $goal) { Piwik_AddMenu($mainGoalMenu, str_replace('%', '%%', Piwik_TranslationWriter::clean($goal['name'])), array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal'])); } } }
protected function trackVisits() { $dateTime = $this->dateTime; $idSite = $this->idSite1; $idSite2 = $this->idSite2; if ($this->allowConversions) { $this->idGoal1 = Piwik_Goals_API::getInstance()->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5); $this->idGoal2 = Piwik_Goals_API::getInstance()->addGoal($idSite2, 'all', 'url', 'http', 'contains'); } // - // First visitor on Idsite 1: two page views $datetimeSpanOverTwoDays = '2010-01-03 23:55:00'; $visitorA = $this->getTracker($idSite, $datetimeSpanOverTwoDays, $defaultInit = true); $visitorA->setUrlReferrer('http://referer.com/page.htm?param=valuewith some spaces'); $visitorA->setUrl('http://example.org/index.htm'); $visitorA->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($datetimeSpanOverTwoDays)->getTimestamp(); $this->checkResponse($visitorA->doTrackPageView('first page view')); $visitorA->setForceVisitDateTime(Piwik_Date::factory($datetimeSpanOverTwoDays)->addHour(0.1)->getDatetime()); // testing with empty URL and empty page title $visitorA->setUrl(' '); $this->checkResponse($visitorA->doTrackPageView(' ')); // - // Second new visitor on Idsite 1: one page view $visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true); $visitorB->setIp('100.52.156.83'); $visitorB->setResolution(800, 300); $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime()); $visitorB->setUrlReferrer(''); $visitorB->setUserAgent('Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1'); $visitorB->setUrl('http://example.org/products'); $visitorB->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($dateTime)->addHour(1)->getTimestamp(); $this->checkResponse($visitorB->doTrackPageView('first page view')); // - // Second visitor again on Idsite 1: 2 page views 2 days later, 2010-01-05 $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->getDatetime()); // visitor_returning is set to 1 only when visit count more than 1 // Temporary, until we implement 1st party cookies in PiwikTracker $visitorB->DEBUG_APPEND_URL .= '&_idvc=2&_viewts=' . Piwik_Date::factory($dateTime)->getTimestamp(); $visitorB->setUrlReferrer('http://referer.com/Other_Page.htm'); $visitorB->setUrl('http://example.org/index.htm'); $this->checkResponse($visitorB->doTrackPageView('second visitor/two days later/a new visit')); // Second page view 6 minutes later $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.1)->getDatetime()); $visitorB->setUrl('http://example.org/thankyou'); $this->checkResponse($visitorB->doTrackPageView('second visitor/two days later/second page view')); // testing a strange combination causing an error in r3767 $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.2)->getDatetime()); $this->checkResponse($visitorB->doTrackAction('mailto:test@example.org', 'link')); $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime()); $this->checkResponse($visitorB->doTrackAction('mailto:test@example.org/strangelink', 'link')); // Actions.getPageTitle tested with this title $visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48)->addHour(0.25)->getDatetime()); $this->checkResponse($visitorB->doTrackPageView('Checkout / Purchasing...')); // - // First visitor on Idsite 2: one page view, with Website referer $visitorAsite2 = $this->getTracker($idSite2, Piwik_Date::factory($dateTime)->addHour(24)->getDatetime(), $defaultInit = true); $visitorAsite2->setUserAgent('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;)'); $visitorAsite2->setUrlReferrer('http://only-homepage-referer.com/'); $visitorAsite2->setUrl('http://example2.com/home'); $visitorAsite2->DEBUG_APPEND_URL = '&_idts=' . Piwik_Date::factory($dateTime)->addHour(24)->getTimestamp(); $this->checkResponse($visitorAsite2->doTrackPageView('Website 2 page view')); // test with invalid URL $visitorAsite2->setUrl('this is invalid url'); // and an empty title $this->checkResponse($visitorAsite2->doTrackPageView('')); // Returning visitor on Idsite 2 1 day later, one page view, with chinese referer // $t2->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(48 + 10)->getDatetime()); // $t2->setUrlReferrer('http://www.baidu.com/s?wd=%D0%C2+%CE%C5&n=2'); // $t2->setUrl('http://example2.com/home'); // $this->checkResponse($t2->doTrackPageView('I\'m a returning visitor...')); }
protected function getGoalReportView($idGoal = false) { $view = Piwik_View::factory('single_goal'); if ($idGoal == Piwik_Archive::LABEL_ECOMMERCE_ORDER) { $goalDefinition['name'] = Piwik_Translate('Goals_Ecommerce'); $goalDefinition['allow_multiple'] = true; $view->ecommerce = true; } else { if (!isset($this->goals[$idGoal])) { Piwik::redirectToModule('Goals', 'index', array('idGoal' => null)); } $goalDefinition = $this->goals[$idGoal]; } $this->setGeneralVariablesView($view); $goal = $this->getMetricsForGoal($idGoal); foreach ($goal as $name => $value) { $view->{$name} = $value; } if ($idGoal == Piwik_Archive::LABEL_ECOMMERCE_ORDER) { $goal = $this->getMetricsForGoal(Piwik_Archive::LABEL_ECOMMERCE_CART); foreach ($goal as $name => $value) { $name = 'cart_' . $name; $view->{$name} = $value; } } $view->idGoal = $idGoal; $view->goalName = $goalDefinition['name']; $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; $view->graphEvolution = $this->getEvolutionGraph(true, array('nb_conversions'), $idGoal); $view->nameGraphEvolution = 'GoalsgetEvolutionGraph' . $idGoal; $view->topDimensions = $this->getTopDimensions($idGoal); // conversion rate for new and returning visitors $segment = 'visitorType==returning,visitorType==returningCustomer'; $conversionRateReturning = Piwik_Goals_API::getInstance()->getConversionRate($this->idSite, Piwik_Common::getRequestVar('period'), Piwik_Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_returning = $this->formatConversionRate($conversionRateReturning); $segment = 'visitorType==new'; $conversionRateNew = Piwik_Goals_API::getInstance()->getConversionRate($this->idSite, Piwik_Common::getRequestVar('period'), Piwik_Common::getRequestVar('date'), $segment, $idGoal); $view->conversion_rate_new = $this->formatConversionRate($conversionRateNew); return $view; }