I'm saving impressions using the Google Measurement protocol API. It works fine but although i'm not echoing anything it returns GIF89a�����,D; which is visible on the page. Any idea how I can hide this?
I'm sending the data using a HTTP post request.
$url = 'http://www.google-analytics.com/collect';
$fields_string = '';
$fields = array(
'v' => 1,
'tid' => 'UA-xxxxxxx-xx',
'cid' => xxx,
't' => 'event',
'ec' => 'category',
'ea' => 'impression',
'el' => 'label'
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
As it stands, when doing your cURL call the returned information will be displayed on the screen. If you want to avoid that you can use CURLOPT_RETURNTRANSFER, which will allow you to store the returned information to a variable like you did.
$result = curl_exec($ch);
Since you're not "telling" curl otherwise it will simply spill the return to the browser.
So finally, you curl part should lok like this:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url); //curl the url
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); //return the transfer to be later saved to a variable
$result = curl_exec($ch);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With