Last active
April 9, 2024 23:22
-
-
Save bemobtrk/528d23bd9a82b99f923aff875aca13d7 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
define('API_ACCESS_KEY', ''); | |
define('API_SECRET_KEY', ''); | |
define('LIVE_REPORT_TYPE', 'live-visits'); | |
define('CAMPAIGN_ID', ''); | |
define('FAKE_CONVERSION_PAYOUT', 0.0); | |
define('POSTBACKS_LIMIT', 1); | |
$ch = curl_init(); | |
curl_setopt_array($ch, [ | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HTTPHEADER => [ | |
'X-ACCESS-KEY: ' . API_ACCESS_KEY, | |
'X-SECRET-KEY: ' . API_SECRET_KEY, | |
], | |
]); | |
$campaignUrl = 'https://api.bemob.com/campaigns/' . CAMPAIGN_ID; | |
$campaignData = null; | |
curl_setopt($ch, CURLOPT_URL, $campaignUrl); | |
$result = curl_exec($ch); | |
$result = json_decode($result, true); | |
if ($result && $result['success']) { | |
$campaignData = $result['payload']; | |
} | |
if (!$campaignData) { | |
throw new \Error('Campaign not found'); | |
} | |
if (!$campaignData['trafficSourceId']) { | |
throw new \Error('No traffic source for this campaign'); | |
} | |
$trafficSourceUrl = 'https://api.bemob.com/traffic-sources/' . $campaignData['trafficSourceId']; | |
$trafficSourceData = null; | |
curl_setopt($ch, CURLOPT_URL, $trafficSourceUrl); | |
$result = curl_exec($ch); | |
$result = json_decode($result, true); | |
if ($result && $result['success']) { | |
$trafficSourceData = $result['payload']; | |
} | |
if (!$trafficSourceData) { | |
throw new \Error('Traffic source not found'); | |
} | |
define('POSTBACK_URL', $trafficSourceData['postbackUrl']); | |
$liveReportUrl = 'https://api.bemob.com/report/' . LIVE_REPORT_TYPE . '?' . http_build_query([ | |
'columns' => [ | |
'reports-timestamp', | |
'reports-externalid', | |
'reports-custom1', | |
'reports-custom2', | |
'reports-custom3', | |
'reports-custom4', | |
'reports-custom5', | |
'reports-custom6', | |
'reports-custom7', | |
'reports-custom8', | |
'reports-custom9', | |
'reports-custom10', | |
'campaigns-id', | |
'traffic_sources-id', | |
'traffic_sources-id', | |
], | |
'currency' => 'USD', | |
'date' => 'today', | |
'filterTables' => ['campaigns'], | |
'filterValues' => [CAMPAIGN_ID], | |
'from' => date('Y-m-d 00:00:00'), | |
'to' => date('Y-m-d 23:59:59'), | |
'orderBy' => 'reports-timestamp', | |
'orderDir' => 'desc', | |
'groupBy' => LIVE_REPORT_TYPE, | |
]); | |
$liveReportData = null; | |
curl_setopt($ch, CURLOPT_URL, $liveReportUrl); | |
$result = curl_exec($ch); | |
$result = json_decode($result, true); | |
if ($result && $result['success']) { | |
$liveReportData = $result['payload']['data']; | |
} | |
curl_close($ch); | |
$postbackCh = curl_init(); | |
curl_setopt($postbackCh, CURLOPT_RETURNTRANSFER, true); | |
$postbacksSent = 0; | |
foreach($liveReportData as $visit) { | |
if ($postbacksSent >= POSTBACKS_LIMIT) { | |
break; | |
} | |
$visitPostbackUrl = POSTBACK_URL; | |
$visitPostbackUrl = str_replace('{transactionId}', '', $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{externalId}', $visit['reports-externalid'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{payout}', number_format(FAKE_CONVERSION_PAYOUT, 4), $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom1}', $visit['reports-custom1'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom2}', $visit['reports-custom2'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom3}', $visit['reports-custom3'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom4}', $visit['reports-custom4'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom5}', $visit['reports-custom5'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom6}', $visit['reports-custom6'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom7}', $visit['reports-custom7'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom8}', $visit['reports-custom8'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom9}', $visit['reports-custom9'], $visitPostbackUrl); | |
$visitPostbackUrl = str_replace('{custom10}', $visit['reports-custom10'], $visitPostbackUrl); | |
curl_setopt($postbackCh, CURLOPT_URL, $visitPostbackUrl); | |
curl_exec($postbackCh); | |
$postbacksSent++; | |
} | |
curl_close($postbackCh); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment