Как получить & quot; метрику & quot; и «элемент» названия для Adobe Analytics

Я получаю отчет, используя Adobe API от Omniture.

Вот полный сценарий:

    <?php

include_once('/path/SimpleRestClient.php');

// Date
$end_date = date("Y-m-d",strtotime("-1 days"));
$start_date = date("Y-m-d",strtotime("-8 days"));


// Location of the files exported
$adobe_file = '/path/Adobe_'.$end_date.'.csv';

// List creation that will be updated with the fields and be put into my CSV file
$list = array
(
array('lasttouchchannel', 'product','visits','CTR(Clicks/PageViews)') // headers // ADD or DELETE metrics #
);

function GetAPIData($method, $data)
{
$username       = "XXXX";
$shared_secret  = "XXXX";
$postURL        = "https://api3.omniture.com/admin/1.4/rest/?method=";

// Nonce is a simple unique id to each call to prevent MITM attacks.
$nonce      = md5(uniqid(php_uname('n'), true));
// The current timestamp in ISO-8601 format
$nonce_ts   = date('c');
/* The Password digest is a concatenation of the nonce, it is timestamp and your password
(from the same location as your username) which runs through SHA1 and then through a base64 encoding */
$digest     = base64_encode(sha1($nonce . $nonce_ts . $shared_secret));

$rc = new SimpleRestClient();
$rc -> setOption(CURLOPT_HTTPHEADER, array("X-WSSE: UsernameToken Username=\"$username\", PasswordDigest=\"$digest\", Nonce=\"$nonce\", Created=\"$nonce_ts\""));
//var_dump($o);

$rc -> postWebRequest($postURL .$method, $data);
return $rc;
}

$method = 'Report.Queue';
$data       ='
{
"reportDescription":
{
"reportSuiteID":"XXXX",
"dateFrom":"'.$start_date.'",
"dateTo":"'.$end_date.'",
"metrics":[{"id":"visits"},{"id":"instances"},{"id":"pageviews"}],
"elements":[{"id":"lasttouchchannel","top":"50000"}]
}
}';
/*
"date":"'.$date.'",
"dateTo":"'.$date.'",
"dateFrom":"'.$start_date.'",
"dateTo":"'.$end_date.'",
*/
$rc=GetAPIData($method, $data);

if($rc -> getStatusCode() == 200) // status code 200 is for 'ok'
{
$counter    = 0;
do
{
if($counter>0){sleep($sleep = 120);}
$return = GetAPIData('Report.Get', $rc->getWebResponse());
$counter++;
}while($return -> getStatusCode() == 400 && json_decode($return->getWebResponse())->error == 'report_not_ready'); // status code 400 is for 'bad request'

//
$json=json_decode($return->getWebResponse());

foreach ($json->report->data as $el)
{
echo $el->name.":".$el->counts[0].":".$el->counts[1]."\n";

// Adding the data in the CSV file without overwriting the previous data
array_push($list, array($el->name, $el->name, $el->counts[0], ($el->counts[1])/($el->counts[2])));
}

}
else
{
echo "Wrong";
}

$fp = fopen($adobe_file, 'w');

foreach ($list as $fields)
{
// Save the data into a CSV file
fputcsv($fp, $fields);
}

fclose($fp);

?>

Как я могу получить названия метрик и элементов, чтобы использовать их в этом скрипте? Выхода нет. Я искал все возможные теги на Google, и ничего не получилось!

Мне нужны метрики и элементы для этой части кода:

$data       ='
{
"reportDescription":
{
"reportSuiteID":"XXXX",
"dateFrom":"'.$start_date.'",
"dateTo":"'.$end_date.'",
"metrics":[{"id":"visits"},{"id":"instances"},{"id":"pageviews"}],
"elements":[{"id":"lasttouchchannel","top":"50000"}]
}
}';

Я не могу найти «дату» как элемент, который имеет решающее значение. Я не могу найти все другие метрики, а также. В Google Analytics у нас была эта ссылка:
Google Analytics Query

но в Adobe нет ни одного. Я хочу что-то подобное:

"metrics":[{"id":"instances"},{"id":"impressions"}],
"elements":[{"id":"date","top":"50000"}]

1

Решение

Ты бы json_decode() как $data содержит строку JSON. Например:

$data ='
{
"reportDescription":
{
"reportSuiteID":"XXXX",
"dateFrom":"'.$start_date.'",
"dateTo":"'.$end_date.'",
"metrics":[{"id":"visits"},{"id":"instances"},{"id":"pageviews"}],
"elements":[{"id":"lasttouchchannel","top":"50000"}]
}
}';


$json = json_decode($data, true);
echo $json['reportDescription']['dateFrom'];
print_r($json['reportDescription']['metrics']);
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector