Skip to content

Instantly share code, notes, and snippets.

@ku-suke ku-suke/ga_ios9block.php
Last active Feb 17, 2016

Embed
What would you like to do?
<?php
$cid = "";
if(isset($_COOKIE["ios9tracking"])&&strlen($_COOKIE["ios9tracking"])==36){
$cid = $_COOKIE["ios9tracking"];
}else{
$cid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
$data['v'] = '1';
$data['tid'] = 'UA-xxxxx-xx';
$data['cid'] = $cid;
$data['t'] = 'pageview';
$data['dh'] = 'hoge.example.com'; // host name
$data['dp'] = '/ios9_blocktrack'; // path name(fixed)
$data['dt'] = '_コンテンツブロック'; // page title
$data['uip'] = $_SERVER['REMOTE_ADDR'];
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
$url = 'http://www.google-analytics.com/collect';
$content = http_build_query($data);
$content = utf8_encode($content);
$user_agent = 'AnalyticsReporter/1.0 (http://blog.ku-suke.jp/)';
$ch = curl_init();
curl_setopt($ch,CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $content);
curl_exec($ch);
curl_close($ch);
header("Content-type: image/gif");
setcookie("ios9tracking", $cid, time()+(3600*24*365)); /* 1 year */
echo base64_decode("R0lGODlhAQABAJEAAAAAAP///////wAAACH5BAEHAAIALAAAAAABAAEAAAICVAEAOw==");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.