我想在非基於Web的應用程序(基於Windows的應用程序)中向Google Analytics(分析)發送請求? 我試過下面的方法。如何在非基於Web的應用程序中向Google Analytics發送請求
public string trackingId = "UA-XXXXXXXX-2";
private void button1_Click(object sender, EventArgs e)
{
string shopname = "ShopTestng";
string pagename="Testing_MyApp";
callAnalyticsmethod2(pagename, shopname);
}
private void callAnalyticsmethod2(string pageName, string shopname)
{
// create hash code base on pc name 7 user name
string visitorId = GetUniqueUserId();
if (string.IsNullOrEmpty(pageName))
pageName = visitorId;
string utmGifLocation = "http://www.google-analytics.com/__utm.gif";
string GifUrl = "utmwv=4.9" +
"&utmn=" + GetRandomNumber() +
"&utmp=" + pageName +
"&utmac=" + trackingId +
"&utmcc=__utma%3D999.999.999.999.999.1%3B" +
"&utmvid=" + visitorId;// + "?" +
string shop = shopname.Replace(" ", "_");
string addipara = GifUrl+"&utmr=http://" + shop;
byte[] dataStream = Encoding.UTF8.GetBytes(addipara);
string request = utmGifLocation;
WebRequest webRequest = WebRequest.Create(request);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = dataStream.Length;
Stream newStream = webRequest.GetRequestStream();
// Send the data.
newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
WebResponse webResponse = webRequest.GetResponse();
MessageBox.Show((((HttpWebResponse)webResponse).StatusDescription));
newStream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(newStream);
string responseFromServer = reader.ReadToEnd();
MessageBox.Show(responseFromServer);
reader.Close();
newStream.Close();
webResponse.Close();
}
根據上述代碼示例
MessageBox.Show((((HttpWebResponse)webResponse).StatusDescription));
線顯示爲 「OK」。但是當我檢查谷歌分析時,訪問計數不會增加。這是什麼原因? 有什麼我缺少或任何其他方式發送請求分析?
如何轉關閉那些過濾器? – DevT
仍然無法更新計數... :( – DevT
我還沒有分配任何過濾器...但它沒有更新... – DevT