如何获取 PHP 的 "metric" 和 "element" 名称 - Adob​​e Analytics

How to get "metric" and "element" names for PHP - Adobe Analytics

我正在使用来自 Omniture 的 Adob​​e API 提取报告。

这是完整的脚本:

    <?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"}]
                }
            }';

我找不到 'date' 作为关键元素。我也找不到所有其他指标。在 Google Analytics 中,我们有这个 link : Google Analytics Query

但在 Adob​​e 中没有。我想要这样的东西:

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

你会 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']);