जवाबों:
Analytics डेटा को सर्वर-साइड से ट्रैक करना अब (और आसान) संभव है। यूनिवर्सल एनालिटिक्स के लॉन्च के साथ, अब आप जीए सर्वर पर डेटा पोस्ट करने के लिए मापन प्रोटोकॉल का उपयोग कर सकते हैं ।
using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
public class GoogleAnalyticsApi
{
public static void TrackEvent(string type, string category,
string action, string label, string value)
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData =
"v=1&tid=UX-XXXXXXX-1&cid=1234&t=" + type +
"&ec=" + category +
"&ea=" + action +
"&el=" + label +
"&ev=" + value;
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.google-analytics.com/collect");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
}
यदि आप PHP का उपयोग करते हैं, तो आप Google Analytics खाते में पृष्ठ दृश्य भेजने के लिए 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');
उम्मीद है की वो मदद करदे!
उपयोग-सांख्यिकी मॉड्यूल पर एक नज़र डालें ।
शेल स्क्रिप्ट में आँकड़ों को ट्रैक करना:
# Track an event: category 'Backup', action 'start'
usage-stats event --tid UA-98765432-1 --ec Backup --ea start
# Perform the backup
cp files/** backup/
# Track an event: category 'Backup', action 'complete'
usage-stats event --tid UA-98765432-1 --ec Backup --ea complete
सबसे तुच्छ उदाहरण।
const UsageStats = require('usage-stats')
const usageStats = new UsageStats('UA-98765432-1', { an: 'example' })
usageStats.screenView('screen name')
usageStats.event('category', 'action')
usageStats.send()