Created
September 30, 2016 19:54
-
-
Save dbrent-amazon/46d660dafa22b619c83ab8465d7f7565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* requestReport */ | |
$req = $client->requestReport( | |
"productAds", | |
array("reportDate" => "20160916", | |
"campaignType" => "sponsoredProducts", | |
"metrics" => "impressions,clicks,cost,attributedConversions30dSameSKU,attributedConversions30d,attributedSales30dSameSKU,attributedSales30d")); | |
/* getReport */ | |
$req = $client->getReport("REPORT_ID"); | |
file_put_contents("/Users/dbrent/Downloads/report.json", $req["response"]); | |
Then I processed the data like so: | |
$report_json = json_decode(file_get_contents("/Users/dbrent/Downloads/report.json"), true); | |
$tsv = "sku\tasin\tadId\tclicks\timpressions\tattributedSales30dSameSKU\tattributedSales30d\tattributedConversions30dSameSKU\tattributedConversions30d\n"; | |
foreach ($report_json as $rj) { | |
$clicks = ""; | |
$impressions = ""; | |
$adId = $rj["adId"]; | |
$clicks = $rj["clicks"]; | |
$impressions = $rj["impressions"]; | |
echo "Processing {$adId}\n"; | |
$req = $client->getProductAd($adId); | |
$json_ad = json_decode($req["response"], true); | |
$sku = $json_ad["sku"]; | |
$asin = $json_ad["asin"]; | |
$tsv .= "{$sku}\t{$asin}\t{$adId}\t{$clicks}\t{$impressions}\t{$rj['attributedSales30dSameSKU']}\t{$rj['attributedSales30d']}\t{$rj['attributedConversions30dSameSKU']}\t{$rj['attributedConversions30d']}\n"; | |
usleep(5000); | |
} | |
file_put_contents("/Users/dbrent/Downloads/report.tsv", $tsv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment