If you are tracking Ecommerce orders and products on your site, the functions "getItemsSku", "getItemsName" and "getItemsCategory" will return the list of products purchased on your site, either grouped by Product SKU, Product Name or Product Category. For each name, SKU or category, the following metrics are returned: Total revenue, Total quantity, average price, average quantity, number of orders (or abandoned carts) containing this product, number of visits on the Product page, Conversion rate. By default, these functions return the 'Products purchased'. These functions also accept an optional parameter &abandonedCarts=1. If the parameter is set, it will instead return the metrics for products that were left in an abandoned cart therefore not purchased. The API also lets you request overall Goal metrics via the method "get": Conversions, Visits with at least one conversion, Conversion rate and Revenue. If you wish to request specific metrics about Ecommerce goals, you can set the parameter &idGoal=ecommerceAbandonedCart to get metrics about abandoned carts (including Lost revenue, and number of items left in the cart) or &idGoal=ecommerceOrder to get metrics about Ecommerce orders (number of orders, visits with an order, subtotal, tax, shipping, discount, revenue, items ordered) See also the documentation about Tracking Goals in Piwik.
Inheritance: extends Piwik\Plugin\API
 private function trackVisits()
 {
     $dateTime = $this->dateTime;
     $idSite = 1;
     $idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
     $idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit;
     $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
     // Record 1st goal, should only have 1 conversion
     $t->setUrl('http://example.org/index.htm');
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());
     self::checkResponse($t->doTrackPageView('Thank you mate'));
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
     self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000));
     // Record 2nd goal, should record both conversions
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.5)->getDatetime());
     self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300));
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.6)->getDatetime());
     self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366));
     // Update & set to not allow multiple
     $goals = API::getInstance()->getGoals($idSite);
     $goal = $goals[$idGoal_OneConversionPerVisit];
     self::assertTrue($goal['allow_multiple'] == 0);
     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);
     self::assertTrue($goal['allow_multiple'] == 1);
     // 1st goal should Now be tracked
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.61)->getDatetime());
     self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656));
     // few minutes later, create a new_visit
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.7)->getDatetime());
     $t->setTokenAuth($this->getTokenAuth());
     $t->setForceNewVisit();
     $t->doTrackPageView('This is tracked in a new visit.');
 }
 private function setUpWebsitesAndGoals()
 {
     $ecommerce = $this->allowConversions ? 1 : 0;
     // tests run in UTC, the Tracker in UTC
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime, $ecommerce, "Site 1");
     }
     if (!self::siteCreated($idSite = 2)) {
         self::createWebsite($this->dateTime, 0, "Site 2");
     }
     if ($this->allowConversions) {
         if (!self::goalExists($idSite = 1, $idGoal = 1)) {
             APIGoals::getInstance()->addGoal($this->idSite1, 'all', 'url', 'http', 'contains', false, 5);
         }
         if (!self::goalExists($idSite = 1, $idGoal = 2)) {
             APIGoals::getInstance()->addGoal($this->idSite2, 'all', 'url', 'http', 'contains');
         }
         if (!self::goalExists($idSite = 1, $idGoal = 3)) {
             APIGoals::getInstance()->addGoal($this->idSite1, 'matching URL with campaign parameter', 'url', self::URL_IS_GOAL_WITH_CAMPAIGN_PARAMETERS, 'contains');
         }
     }
     APISitesManager::getInstance()->updateSite($this->idSite1, "Site 1", $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 2);
     // KEEP_URL_FRAGMENT_NO No for idSite 1
     APISitesManager::getInstance()->updateSite($this->idSite2, "Site 2", $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1);
     // KEEP_URL_FRAGMENT_YES Yes for idSite 2
 }
 /**
  * Echo's HTML for visitor profile popup.
  */
 public function getVisitorProfilePopup()
 {
     Piwik::checkUserHasSomeAdminAccess();
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $gotoChat = Common::getRequestVar('chat', '0', 'int');
     $idvisitor = Common::getRequestVar('visitorId', null, 'string');
     if (!$gotoChat) {
         $gotoChat = isset($_SESSION['chatViewByDefault']) ? $_SESSION['chatViewByDefault'] : false;
     }
     $conversation = new ChatConversation($idSite, $idvisitor);
     $messages = $conversation->getAllMessages();
     $infos = ChatPersonnalInformation::get($idvisitor);
     if (count($messages) > 0) {
         $lastMsgIndex = count($messages) - 1;
         ChatAcknowledgment::setLastViewed($idvisitor, $messages[$lastMsgIndex]['microtime'], Piwik::getCurrentUserLogin());
     }
     $view = new View('@Chat/getVisitorProfilePopup.twig');
     $view->idSite = $idSite;
     $view->chat = $gotoChat;
     $view->goals = APIGoals::getInstance()->getGoals($idSite);
     $view->visitorData = Request::processRequest('Live.getVisitorProfile', array('checkForLatLong' => true));
     $view->exportLink = $this->getVisitorProfileExportLink();
     $view->messages = $messages;
     $view->infos = $infos;
     if (Common::getRequestVar('showMap', 1) == 1 && !empty($view->visitorData['hasLatLong']) && \Piwik\Plugin\Manager::getInstance()->isPluginLoaded('UserCountryMap')) {
         $view->userCountryMapUrl = $this->getUserCountryMapUrlForVisitorProfile();
     }
     $this->setWidgetizedVisitorProfileUrl($view);
     return $view->render();
 }
Example #4
0
 public function configureReportingMenu(MenuReporting $menu)
 {
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $goals = API::getInstance()->getGoals($idSite);
     $mainGoalMenu = $this->getGoalCategoryName($idSite);
     $site = new Site($idSite);
     if (count($goals) == 0) {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_AddNewGoal', array('module' => 'Goals', 'action' => 'addNewGoal'));
     } else {
         $menu->add($mainGoalMenu, '', array('module' => 'Goals', 'action' => $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index', 'idGoal' => $site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null), true, 25);
         if ($site->isEcommerceEnabled()) {
             $menu->add($mainGoalMenu, 'Goals_Ecommerce', array('module' => 'Goals', 'action' => 'ecommerceReport', 'idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER), true, 1);
         }
         $menu->add($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), true, 2);
         $group = new Group();
         foreach ($goals as $goal) {
             $subMenuName = str_replace('%', '%%', Translate::clean($goal['name']));
             $params = array('module' => 'Goals', 'action' => 'goalReport', 'idGoal' => $goal['idgoal']);
             $tooltip = sprintf('%s (id = %d)', $subMenuName, $goal['idgoal']);
             if (count($goals) <= 3) {
                 $menu->add($mainGoalMenu, $subMenuName, $params, true, 50, $tooltip);
             } else {
                 $group->add($subMenuName, $params, $tooltip);
             }
         }
         if (count($goals) > 3) {
             $menu->addGroup($mainGoalMenu, 'Goals_ChooseGoal', $group, $orderId = 50, $tooltip = false);
         }
     }
 }
 private function trackVisits()
 {
     // tests run in UTC, the Tracker in UTC
     $dateTime = $this->dateTime;
     $idSite = $this->idSite;
     $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
     // 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!?filter=<script>alert(1);</script>{"place":{"place":"0c5b2444-70a0-4932-980c-b4dc0d3f02b5"}}');
     self::checkResponse($t->doTrackPageView('incredible title! (Page URL contains a HTML entity)'));
     $idGoal = 1;
     if (!self::goalExists($idSite, $idGoal)) {
         $idGoal = API::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
     }
     $t->setForceVisitDateTime(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(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(''));
 }
Example #6
0
 public function __construct(Translator $translator)
 {
     parent::__construct();
     $this->translator = $translator;
     $this->idSite = Common::getRequestVar('idSite', null, 'int');
     $this->goals = API::getInstance()->getGoals($this->idSite);
 }
Example #7
0
 private function getGoalsForIdSite($idSite)
 {
     if (empty($idSite)) {
         return array();
     }
     return API::getInstance()->getGoals($idSite);
 }
 protected function setUpGoals()
 {
     $api = Goals\API::getInstance();
     foreach ($this->goals as $goal) {
         $api->addGoal($this->idSite, $goal['name'], $goal['match'], $goal['pattern'], $goal['patternType'], $caseSensitive = false, $goal['revenue'], $allowMultipleConversionsPerVisit = false);
     }
 }
Example #9
0
 public function configureReportingMenu(MenuReporting $menu)
 {
     $idSite = $this->getIdSite();
     $goals = API::getInstance()->getGoals($idSite);
     $mainGoalMenu = 'Goals_Goals';
     if (count($goals) == 0) {
         $linkToAddNewGoal = $this->urlForAction('addNewGoal', array('idGoal' => null));
         $menu->addItem($mainGoalMenu, '', $linkToAddNewGoal, 25);
         $menu->addItem($mainGoalMenu, 'Goals_AddNewGoal', $linkToAddNewGoal, 1);
         return;
     }
     $order = 1;
     $url = $this->urlForAction('index', array('idGoal' => null));
     $menu->addItem($mainGoalMenu, '', $url, 25);
     $menu->addItem($mainGoalMenu, 'General_Overview', $url, ++$order);
     $group = new Group();
     foreach ($goals as $goal) {
         $subMenuName = str_replace('%', '%%', Translate::clean($goal['name']));
         $params = $this->urlForAction('goalReport', array('idGoal' => $goal['idgoal']));
         $tooltip = sprintf('%s (id = %d)', $subMenuName, $goal['idgoal']);
         if (count($goals) > 3) {
             $group->add($subMenuName, $params, $tooltip);
         } else {
             $menu->addItem($mainGoalMenu, $subMenuName, $params, ++$order, $tooltip);
         }
     }
     if (count($goals) > 3) {
         $menu->addGroup($mainGoalMenu, 'Goals_ChooseGoal', $group, ++$order, $tooltip = false);
     }
     $menu->addItem($mainGoalMenu, 'Goals_ManageGoals', $this->urlForAction('editGoals'), ++$order);
 }
Example #10
0
 public function getSparklines()
 {
     $idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER;
     $view = new View('@Ecommerce/getSparklines');
     $view->onlyConversionOverview = false;
     $view->conversionsOverViewEnabled = true;
     if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
         $goalDefinition['name'] = $this->translator->translate('Goals_Ecommerce');
         $goalDefinition['allow_multiple'] = true;
     } else {
         $goals = GoalsApi::getInstance()->getGoals($this->idSite);
         if (!isset($goals[$idGoal])) {
             Piwik::redirectToModule('Goals', 'index', array('idGoal' => null));
         }
         $goalDefinition = $goals[$idGoal];
     }
     $this->setGeneralVariablesView($view);
     $goal = $this->getMetricsForGoal($idGoal);
     foreach ($goal as $name => $value) {
         $view->{$name} = $value;
     }
     if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
         $goal = $this->getMetricsForGoal(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART);
         foreach ($goal as $name => $value) {
             $name = 'cart_' . $name;
             $view->{$name} = $value;
         }
     }
     $view->idGoal = $idGoal;
     $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple'];
     return $view->render();
 }
 public function setUp()
 {
     // add one site
     Fixture::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/");
     // add two goals
     $goals = API::getInstance();
     $goals->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
     $goals->addGoal($this->idSite, 'all', 'url', 'thing2', 'contains');
     $start = Date::factory($this->date);
     $dates = array();
     for ($day = 0; $day != 31; ++$day) {
         $dates[] = $start->addDay($day);
     }
     $t = BenchmarkTestCase::getLocalTracker($this->idSite);
     $actionNum = 0;
     foreach ($dates as $date) {
         for ($visitNum = 0; $visitNum != 1000; ++$visitNum) {
             if ($visitNum % 2 == 0) {
                 $url = "http://whatever.com/{$actionNum}/0/1/2/3/4/5/6/7/8/9";
                 $referrerUrl = "http://google.com/?q={$actionNum}";
             } else {
                 $url = "http://whatever.com/thing2/{$actionNum}/0/1/2/3/4/5/6/7/8/9";
                 $referrerUrl = "http://";
             }
             $title = "A page title / {$actionNum} / 0 / 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 /9";
             $t->setNewVisitorId();
             $t->setForceVisitDateTime($date);
             $t->setUrl($url);
             $t->setUrlReferrer($referrerUrl);
             Fixture::checkResponse($t->doTrackPageView($title));
             ++$actionNum;
         }
     }
 }
Example #12
0
 /**
  * @param bool $standalone When set to true, the Top controls will be hidden to provide better full screen view
  * @param bool $fetch
  * @param bool|string $segmentOverride
  *
  * @return string
  */
 public function realtimeMap($standalone = false, $fetch = false, $segmentOverride = false)
 {
     $this->checkUserCountryPluginEnabled();
     $idSite = Common::getRequestVar('idSite', 1, 'int');
     Piwik::checkUserHasViewAccess($idSite);
     $token_auth = Piwik::getCurrentUserTokenAuth();
     $view = new View('@UserCountryMap/realtimeMap');
     $view->mapIsStandaloneNotWidget = $standalone;
     $view->metrics = $this->getMetrics($idSite, 'range', self::REAL_TIME_WINDOW, $token_auth);
     $view->defaultMetric = 'nb_visits';
     $liveRefreshAfterMs = (int) Config::getInstance()->General['live_widget_refresh_after_seconds'] * 1000;
     $goals = APIGoals::getInstance()->getGoals($idSite);
     $site = new Site($idSite);
     $hasGoals = !empty($goals) || $site->isEcommerceEnabled();
     // maximum number of visits to be displayed in the map
     $maxVisits = Common::getRequestVar('filter_limit', 100, 'int');
     // some translations
     $locale = array('nb_actions' => Piwik::translate('VisitsSummary_NbActionsDescription'), 'local_time' => Piwik::translate('VisitTime_ColumnLocalTime'), 'from' => Piwik::translate('General_FromReferrer'), 'seconds' => Piwik::translate('UserCountryMap_Seconds'), 'seconds_ago' => Piwik::translate('UserCountryMap_SecondsAgo'), 'minutes' => Piwik::translate('UserCountryMap_Minutes'), 'minutes_ago' => Piwik::translate('UserCountryMap_MinutesAgo'), 'hours' => Piwik::translate('UserCountryMap_Hours'), 'hours_ago' => Piwik::translate('UserCountryMap_HoursAgo'), 'days_ago' => Piwik::translate('UserCountryMap_DaysAgo'), 'actions' => Piwik::translate('VisitsSummary_NbPageviewsDescription'), 'searches' => Piwik::translate('UserCountryMap_Searches'), 'goal_conversions' => Piwik::translate('UserCountryMap_GoalConversions'));
     $segment = $segmentOverride ?: Request::getRawSegmentFromRequest() ?: '';
     $params = array('period' => 'range', 'idSite' => $idSite, 'segment' => $segment, 'token_auth' => $token_auth);
     $realtimeWindow = Common::getRequestVar('realtimeWindow', self::REAL_TIME_WINDOW, 'string');
     if ($realtimeWindow != 'false') {
         // handle special value
         $params['date'] = $realtimeWindow;
     }
     $reqParams = $this->getEnrichedRequest($params, $encode = false);
     $view->config = array('metrics' => array(), 'svgBasePath' => $view->piwikUrl . 'plugins/UserCountryMap/svg/', 'liveRefreshAfterMs' => $liveRefreshAfterMs, '_' => $locale, 'reqParams' => $reqParams, 'siteHasGoals' => $hasGoals, 'maxVisits' => $maxVisits, 'changeVisitAlpha' => Common::getRequestVar('changeVisitAlpha', true, 'int'), 'removeOldVisits' => Common::getRequestVar('removeOldVisits', true, 'int'), 'showFooterMessage' => Common::getRequestVar('showFooterMessage', true, 'int'), 'showDateTime' => Common::getRequestVar('showDateTime', true, 'int'), 'doNotRefreshVisits' => Common::getRequestVar('doNotRefreshVisits', false, 'int'), 'enableAnimation' => Common::getRequestVar('enableAnimation', true, 'int'), 'forceNowValue' => Common::getRequestVar('forceNowValue', false, 'int'));
     return $view->render();
 }
 private function setUpWebsitesAndGoals()
 {
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
     }
 }
Example #14
0
 private function addGoalsWidgets(WidgetsList $widgetsList, $idSite)
 {
     $widgetsList->add('Goals_Goals', 'Goals_GoalsOverview', 'Goals', 'widgetGoalsOverview');
     $goals = API::getInstance()->getGoals($idSite);
     if (count($goals) > 0) {
         foreach ($goals as $goal) {
             $widgetsList->add('Goals_Goals', Common::sanitizeInputValue($goal['name']), 'Goals', 'widgetGoalReport', array('idGoal' => $goal['idgoal']));
         }
     }
 }
 private function setUpWebsitesAndGoals()
 {
     // tests run in UTC, the Tracker in UTC
     if (!self::siteCreated($this->idSite)) {
         self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($this->idSite, $this->idGoal)) {
         API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
     }
 }
 /**
  * @depends      testApi
  */
 public function testCheck()
 {
     $idSite = self::$fixture->idSite;
     // test delete is working as expected
     $goals = API::getInstance()->getGoals($idSite);
     $this->assertTrue(5 == count($goals));
     API::getInstance()->deleteGoal($idSite, self::$fixture->idGoal_OneConversionPerVisit);
     API::getInstance()->deleteGoal($idSite, self::$fixture->idGoal_MultipleConversionPerVisit);
     $goals = API::getInstance()->getGoals($idSite);
     $this->assertTrue(3 == count($goals));
 }
 private function setUpWebsitesAndGoals()
 {
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
     }
     if (!self::goalExists($idSite = 1, $idGoal = 2)) {
         API::getInstance()->addGoal($this->idSite, 'view act', 'url', 'http://mutantregistration.com/act.html', 'exact');
     }
 }
Example #18
0
 private function setUpWebsitesAndGoals()
 {
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime, 0, "Site 1");
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         $this->idGoal = API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 2)) {
         $this->idGoal2 = API::getInstance()->addGoal($this->idSite, 'two', 'url', 'xxxxxxxxxxxxx', 'contains', false, 5);
     }
 }
 private function setUpWebsitesAndGoals()
 {
     // tests run in UTC, the Tracker in UTC
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         // These two goals are to check events don't trigger for URL or Title matching
         APIGoals::getInstance()->addGoal($this->idSite, 'triggered js', 'url', 'webradio', 'contains');
         APIGoals::getInstance()->addGoal($this->idSite, 'triggered js', 'title', 'Music', 'contains');
     }
 }
 private function setUpWebsitesAndGoals()
 {
     if (!self::siteCreated($this->idSite)) {
         $this->idSite = self::createWebsite($this->dateTime, $ecommerce = 1);
     }
     if (!self::siteCreated($this->idSite2)) {
         $this->idSite2 = self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($this->idSite, $this->idGoalStandard)) {
         API::getInstance()->addGoal($this->idSite, 'title match, triggered ONCE', 'title', 'incredible', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = true);
     }
 }
Example #21
0
 protected function init()
 {
     $this->addWidget('Goals_GoalsOverview', 'widgetGoalsOverview');
     $idSite = $this->getIdSite();
     $goals = API::getInstance()->getGoals($idSite);
     if (count($goals) > 0) {
         foreach ($goals as $goal) {
             $name = Common::sanitizeInputValue($goal['name']);
             $params = array('idGoal' => $goal['idgoal']);
             $this->addWidget($name, 'widgetGoalReport', $params);
         }
     }
 }
 public function setUpWebsitesAndGoals()
 {
     // for conversion testing
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         APIGoals::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5);
     }
     if (!self::siteCreated($idSite = 2)) {
         self::createWebsite($this->dateTime, $ecommerce = 0, $siteName = 'Piwik test two', $siteUrl = 'http://example-site-two.com');
     }
 }
 protected function getGoalName()
 {
     if ($this->idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
         return Piwik::translate('Goals_EcommerceOrder');
     }
     if (isset($this->idSite)) {
         $allGoals = GoalsAPI::getInstance()->getGoals($this->idSite);
         $goalName = @$allGoals[$this->idGoal]['name'];
         return Common::sanitizeInputValue($goalName);
     } else {
         return "";
     }
 }
Example #24
0
 public function __construct(Translator $translator)
 {
     parent::__construct();
     $this->translator = $translator;
     $this->idSite = Common::getRequestVar('idSite', null, 'int');
     $this->goals = API::getInstance()->getGoals($this->idSite);
     foreach ($this->goals as &$goal) {
         $goal['name'] = Common::sanitizeInputValue($goal['name']);
         if (isset($goal['pattern'])) {
             $goal['pattern'] = Common::sanitizeInputValue($goal['pattern']);
         }
     }
 }
 private function setUpWebsitesAndGoals()
 {
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($this->dateTime, $ecommerce = 1);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         API::getInstance()->addGoal($this->idSite, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 2)) {
         API::getInstance()->addGoal($this->idSite, 'Goal 2 - Hello', 'url', 'hellow', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 0);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 3)) {
         API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
     }
 }
 private function setUpWebsitesAndGoals()
 {
     $siteCreated = $this->dateTime;
     if (!self::siteCreated($idSite = 1)) {
         self::createWebsite($siteCreated);
     }
     if (!self::goalExists($idSite = 1, $idGoal = 1)) {
         API::getInstance()->addGoal($this->idSite, 'triggered php', 'manually', '', '');
     }
     if (!self::goalExists($idSite = 1, $idGoal = 2)) {
         API::getInstance()->addGoal($this->idSite, 'another triggered php', 'manually', '', '', false, false, true);
     }
     if (!self::siteCreated($idSite = 2)) {
         self::createWebsite($siteCreated);
     }
 }
 public function setUp()
 {
     $goals = APIGoals::getInstance();
     // add one thousand sites
     $allIdSites = array();
     for ($i = 0; $i < 1000; ++$i) {
         $allIdSites[] = Fixture::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 = 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($idSite);
                 $ip = "157.5.6." . ($visitor + 1);
                 $t->setIp($ip);
                 $t->setNewVisitorId();
                 $t->setForceVisitDateTime($visitTime);
                 foreach ($urls as $url => $title) {
                     $t->setUrl($url);
                     $t->doTrackPageView($title);
                 }
             }
         }
     }
 }
Example #28
0
 protected function init()
 {
     $this->addWidget('Goals_GoalsOverview', 'widgetGoalsOverview');
     $idSite = $this->getIdSite();
     $goals = API::getInstance()->getGoals($idSite);
     if (count($goals) > 0) {
         foreach ($goals as $goal) {
             $name = Common::sanitizeInputValue($goal['name']);
             $params = array('idGoal' => $goal['idgoal']);
             $this->addWidget($name, 'widgetGoalReport', $params);
         }
     }
     $site = new Site($idSite);
     if ($site->isEcommerceEnabled()) {
         $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceOverview', 'widgetGoalReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER));
         $this->addWidgetWithCustomCategory('Goals_Ecommerce', 'Goals_EcommerceLog', 'getEcommerceLog');
     }
 }
 public function setUp()
 {
     for ($i = 0; $i != $this->siteCount; ++$i) {
         $idSite = Fixture::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #{$i}", $siteUrl = "http://site{$i}.com/");
         API::getInstance()->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5);
     }
     // track one visit for each site
     $t = BenchmarkTestCase::getLocalTracker(1);
     $t->setForceVisitDateTime(Date::factory($this->date)->addHour(6));
     for ($idSite = 1; $idSite < $this->siteCount + 1; ++$idSite) {
         $ip = "157.5.6.4";
         $t->setIp($ip);
         $t->setNewVisitorId();
         $t->setIdSite($idSite);
         $t->setUrl("http://site" . ($idSite - 1) . ".com/page.html");
         $t->doTrackPageView('page title');
     }
 }
Example #30
0
 public static function configure(WidgetConfig $config)
 {
     $idSite = Common::getRequestVar('idSite', 0, 'int');
     $config->setCategoryId('Goals_Goals');
     $config->setSubcategoryId('Goals_ManageGoals');
     $config->setIsNotWidgetizable();
     if (empty($idSite)) {
         $config->disable();
         return;
     }
     $goals = API::getInstance()->getGoals($idSite);
     if (Piwik::isUserHasAdminAccess($idSite)) {
         $config->setName('Goals_ManageGoals');
     } else {
         $config->setName('Goals_CreateNewGOal');
     }
     if (count($goals) === 0) {
         $config->disable();
     }
 }