177 $cacheString =
'analytics_yandex_currency';
178 $cachePath =
'/seo/analytics/yandex/';
180 $cache = Cache::createInstance();
182 if($cache->initCache($cacheTime, $cacheString, $cachePath))
184 $currency = $cache->getVars()[
'currency'];
188 $cache->clean($cacheString, $cachePath);
189 $cache->startDataCache($cacheTime);
196 'SelectionCriteria' =>
new \stdClass(),
197 'FieldNames' => [
'Currency'],
206 $response = Json::decode($response);
207 if(!isset($response[
'error']) && isset($response[
'result']) && isset($response[
'result'][
'Campaigns']))
209 foreach($response[
'result'][
'Campaigns'] as $campaign)
219 $cache->endDataCache([
'currency' =>
$currency]);
266 if(!is_string($data) || empty($data))
272 $strings = explode(
"\n", $data);
273 foreach($strings as $number => $string)
277 $titles = explode(
"\t", $string);
279 elseif(!empty($string) && mb_strpos($string,
'Total') !== 0)
281 $row = array_combine($titles, explode(
"\t", $string));
287 $conversions = (is_numeric($result[
'Conversions']) && $result[
'Conversions'])
288 ? $result[
'Conversions']
290 $clicks = (is_numeric($result[
'Clicks']) && $result[
'Clicks'])
295 'impressions' => $result[
'Impressions'],
296 'clicks' => $result[
'Clicks'],
297 'actions' => $conversions + $clicks,
298 'spend' => $result[
'Cost'],
299 'cpc' => $result[
'AvgCpc'],
300 'cpm' => $result[
'AvgCpm'],