I want to create a custom report containing all keywords of a campaign with a specific name.
For this purpose I have the following code so far:
public function getOTHAWCampaign($idSite, $period, $date, $segment = false)
{
$data = \Piwik\API\Request::processRequest('Referrers.getCampaigns', array(
'idSite' => $idSite,
'period' => $period,
'date' => $date,
'segment' => $segment,
'doNotFetchActions' => true,
));
$data->applyQueuedFilters();
foreach ($data->getRows() as $visitRow) {
if ($visitRow->getColumn('label') === "othaw") {
$id = $visitRow->subtableId;
var_dump($visitRow);
}
}
return $this->getKeywordsByCampaignId($idSite, $period, $date, $segment, $id);
}
public function getKeywordsByCampaignId($idSite, $period, $date, $segment, $idsubtable)
{
$result = \Piwik\API\Request::processRequest('Referrers.getKeywordsFromCampaignId', array(
'idSite' => $idSite,
'period' => $period,
'date' => $date,
'idSubtable' => $idsubtable,
'segment' => $segment,
'doNotFetchActions' => false
));
$result->applyQueuedFilters();
return $result;
}
Now when I try to open the Row Evolution, I get this error message:
This seems to be because of the foreach-statement, if I remove it and change $id to a certain number in the function call getKeywordsByCampaignId(), I can open the Row Evolution without any problems.
But the id can change from day to day, if I have understood correctly.
Does anyone know how I can solve this?