コード例 #1
0
 public function getAnotherApiToTest()
 {
     $table = Piwik_CustomVariables_API::getInstance()->getCustomVariables($this->idSite, 'day', '2010-01-03');
     $idsubtable = reset($table->getRows())->getIdSubDataTable();
     // test getProcessedReport w/ custom variables
     return array(array('API.getProcessedReport', array('idSite' => $this->idSite, 'date' => $this->dateTime, 'periods' => 'day', 'apiModule' => 'CustomVariables', 'apiAction' => 'getCustomVariablesValuesFromNameId', 'testSuffix' => '__subtable', 'otherRequestParameters' => array('idSubtable' => $idsubtable))));
 }
コード例 #2
0
ファイル: API.php プロジェクト: Gninety/Microweber
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
コード例 #3
0
ファイル: API.php プロジェクト: nnnnathann/piwik
 protected function enrichItemsDataTableWithItemsViewMetrics($dataTable, $idSite, $period, $date, $idSubtable)
 {
     $ecommerceViews = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = true);
     // For Product names and SKU reports, and for Category report
     // Use the Price (tracked on page views)
     // ONLY when the price sold in conversions is not found (ie. product viewed but not sold)
     foreach ($ecommerceViews->getRows() as $rowView) {
         // If there is not already a 'sum price' for this product
         $rowFound = $dataTable->getRowFromLabel($rowView->getColumn('label'));
         $price = $rowFound ? $rowFound->getColumn(Piwik_Archive::INDEX_ECOMMERCE_ITEM_PRICE) : false;
         if (empty($price)) {
             // If a price was tracked on the product page
             if ($rowView->getColumn(Piwik_Archive::INDEX_ECOMMERCE_ITEM_PRICE_VIEWED)) {
                 $rowView->renameColumn(Piwik_Archive::INDEX_ECOMMERCE_ITEM_PRICE_VIEWED, 'avg_price');
             }
         }
         $rowView->deleteColumn(Piwik_Archive::INDEX_ECOMMERCE_ITEM_PRICE_VIEWED);
     }
     $dataTable->addDataTable($ecommerceViews);
 }
コード例 #4
0
ファイル: API.php プロジェクト: nomoto-ubicast/piwik
 public function getSiteSearchCategories($idSite, $period, $date, $segment = false)
 {
     Piwik_Actions::checkCustomVariablesPluginEnabled();
     $customVariables = Piwik_CustomVariables_API::getInstance()->getCustomVariables($idSite, $period, $date, $segment, $expanded = false, $_leavePiwikCoreVariables = true);
     $customVarNameToLookFor = Piwik_Tracker_Action::CVAR_KEY_SEARCH_CATEGORY;
     $dataTable = new Piwik_DataTable();
     // Handle case where date=last30&period=day
     // TODO: this logic should really be refactored somewhere, this is ugly!
     if ($customVariables instanceof Piwik_DataTable_Array) {
         $dataTable = new Piwik_DataTable_Array();
         $dataTable->metadata = $customVariables->metadata;
         $dataTable->setKeyName($customVariables->getKeyName());
         $customVariableDatatables = $customVariables->getArray();
         $dataTables = $dataTable->getArray();
         foreach ($customVariableDatatables as $key => $customVariableTableForDate) {
             // we do not enter the IF, in the case idSite=1,3 AND period=day&date=datefrom,dateto,
             if (isset($dataTable->metadata[$key]['period'])) {
                 $row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
                 if ($row) {
                     $dateRewrite = $dataTable->metadata[$key]['period']->getDateStart()->toString();
                     $idSubtable = $row->getIdSubDataTable();
                     $categories = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment);
                     $dataTable->addTable($categories, $key);
                 }
             }
         }
     } elseif ($customVariables instanceof Piwik_DataTable) {
         $row = $customVariables->getRowFromLabel($customVarNameToLookFor);
         if ($row) {
             $idSubtable = $row->getIdSubDataTable();
             $dataTable = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment);
         }
     }
     $this->filterActionsDataTable($dataTable);
     $this->addPagesPerSearchColumn($dataTable, $columnToRead = 'nb_actions');
     return $dataTable;
 }
コード例 #5
0
ファイル: API.php プロジェクト: BackupTheBerlios/oos-svn
	/**
	 * Returns a datatable of Items SKU/name or categories and their metrics
	 * If $abandonedCarts set to 1, will return items abandoned in carts. If set to 0, will return items ordered
	 */
	protected function getItems($recordName, $idSite, $period, $date, $abandonedCarts )
	{
		Piwik::checkUserHasViewAccess( $idSite );
		$recordNameFinal = $recordName;
		if($abandonedCarts)
		{
			$recordNameFinal = Piwik_Goals::getItemRecordNameAbandonedCart($recordName);
		}
		$archive = Piwik_Archive::build($idSite, $period, $date );
		$dataTable = $archive->getDataTable($recordNameFinal);
		$dataTable->filter('Sort', array(Piwik_Archive::INDEX_ECOMMERCE_ITEM_REVENUE));
		$dataTable->queueFilter('ReplaceColumnNames');
		
		$ordersColumn = 'orders';
		if($abandonedCarts)
		{
			$ordersColumn = 'abandoned_carts';
			$dataTable->renameColumn(Piwik_Archive::INDEX_ECOMMERCE_ORDERS, $ordersColumn);
		}
		// Average price = sum product revenue / quantity
		$dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_price', 'price', $ordersColumn, Piwik_Tracker_GoalManager::REVENUE_PRECISION));

		// Average quantity = sum product quantity / abandoned carts 
		$dataTable->queueFilter('ColumnCallbackAddColumnQuotient', array('avg_quantity', 'quantity', $ordersColumn, $precision = 1));
		$dataTable->queueFilter('ColumnDelete', array('price'));
		
		// Enrich the datatable with Product/Categories views, and conversion rates
		$mapping = array(
			'Goals_ItemsSku' => '_pks',
			'Goals_ItemsName' => '_pkn',
			'Goals_ItemsCategory' => '_pkc',
		);
		$customVariables = Piwik_CustomVariables_API::getInstance()->getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, $_leavePiwikCoreVariables = true);
		if($customVariables instanceof Piwik_DataTable
			&& $row = $customVariables->getRowFromLabel($mapping[$recordName]))
		{
			// Request views for all products/categories
			$idSubtable = $row->getIdSubDataTable();
			$ecommerceViews = Piwik_CustomVariables_API::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable);
			
			$dataTable->addDataTable($ecommerceViews);
			// Product conversion rate = orders / visits 
			$dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('conversion_rate', $ordersColumn, 'nb_visits', Piwik_Tracker_GoalManager::REVENUE_PRECISION));
		}
		
		return $dataTable;
	}