หากคุณใช้ PHP คุณสามารถโทรหาโปรโตคอลการวัด Analyticsเพื่อส่งการดูหน้าเว็บให้กับบัญชี Google Analytics ของคุณ:
function sendAnalytics($sGaId, $sHostname, $sPath, $sTitle) {
$aParams = array();
//Protocol Version
$aParams['v'] = '1';
//Tracking ID / Web Property ID
$aParams['tid'] = $sGaId;
//Anonymize IP
$aParams['aip'] = '1';
//Data Source
$aParams['ds'] = 'web';
//Queue Time
$aParams['qt'] = 0;
//Client ID
$aParams['cid'] = substr(md5($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']), 0, 8);
//User ID
//$aParams['uid'] = '';
//Session Control
//$aParams[''] = '';
//IP Override
$aParams['uip'] = $_SERVER['REMOTE_ADDR'];
//User Agent Override
$aParams['ua'] = urlencode($_SERVER['HTTP_USER_AGENT']);
//Geographical Override
//$aParams['geoid'] = '';
//Document Referrer
//$aParams['dr'] = '';
//Campaign Name
//$aParams['cn'] = '';
//Campaign Source
//$aParams['cs'] = '';
//Campaign Medium
//$aParams['cm'] = '';
//Campaign Keyword
//$aParams['ck'] = '';
//Campaign Content
//$aParams['cc'] = '';
//Campaign ID
//$aParams['ci'] = '';
//Google AdWords ID
//$aParams['gclid'] = '';
//Google Display Ads ID
//$aParams[''] = '';
////SystemInfo => see docs
//Hit type
$aParams['t'] = 'pageview';
//Non-Interaction Hit
//$aParams['ni'] = '';
//Hostname
$aParams['dh'] = $sHostname;
//Document Path
$aParams['dp'] = $sPath;
//Document title
$aParams['dt'] = urlencode($sTitle);
$sGaUrl = 'http://www.google-analytics.com/collect?';
foreach($aParams AS $sKey => $sValue) {
$sGaUrl.= "$sKey=$sValue&";
}
$sGaUrl = substr($sGaUrl, 0, -1);
file_get_contents($sGaUrl);
}
sendAnalytics('UA-XXXXXXXX-1', 'http://foo.com', '/bar', 'Foo Bar');
หวังว่าจะช่วย!