是否有可能采用做为Gdata API C#发布windows窗体命中信息,以谷歌分析(轨道ID) [英] Is it possible to post windows form Hit info to Google analytics(track id) using Gdata API C#

查看:134
本文介绍了是否有可能采用做为Gdata API C#发布windows窗体命中信息,以谷歌分析(轨道ID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能这是许多非常愚蠢的问题。

May be this is a very dumb question to many.

我已经创建了一个有效的轨道ID一个谷歌分析的A / C。现在,我已经把通过谷歌分析提供给我的* .aspx文件中的JavaScript代码,可以看到我的网站在谷歌分析网站打信息。

I have created a Google analytics a/c with a valid track id. Now I have put the javascript code provided by Google analytics to my *.aspx files and could see my Website hit information in Google analytics site.

现在我可以做同样的距离Windows窗体应用程序?

Now can I do same from a Windows form application?

我想简单的HTTP POST到GA网站,但失败了。我提到以下链接: https://developers.google.com/分析/ devguides /收集/协议/ V1 / devguide#概述

I tried simple Http post to GA site but failed. I referred following link: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#overview

然后我碰到的GData API。 https://code.google.com/archive/p/google-gdata/结果
我已经安装的GData,但不知道如何发送Windows窗体应用程序打信息谷歌分析。

Then I came across GData API. https://code.google.com/archive/p/google-gdata/
I have installed GData but not sure how to send Windows form application hit information to Google analytics.

推荐答案

现在有点在网上搜索后,我碰到下面的链接
传来的
http://tilr.blogspot.com/2012/10/google-analytics-use -Google-analytics.html

Now after a bit of online search, I came across of the below link http://tilr.blogspot.com/2012/10/google-analytics-use-google-analytics.html

测试。正确地工作。您需要提供有效的GA轨道ID和WinForm的名称。

Tested. Works correctly. You need to provide valid GA track Id and winform name.

我还没有改变其他GA设置(唯一visitorid,位置等)。可能是我能帮助的时候我完全理解的方法和参数。

I have not yet changed other GA settings (unique visitorid, location etc.). May be I could help when I fully understand the methods and parameters.

检查此链接:
https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview#gifRequestClassification

http://www.analyticsmarket.com/blog/__utmgif-data 有关参数的详细信息。

Check this link: https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview#gifRequestClassification or http://www.analyticsmarket.com/blog/__utmgif-data for detailed information on the parameters.

从C#WinForm应用程序的最后工作代码:

Final working code from C# winform application:

///<summary>Send winform hit info to Google Analytic</summary>
///<param name="visitorID">Unique visitor id to be set once per session</param>
///<param name="timeStamp">timestamp to be set once per session</param>
///<param name="formName">Name of the winform</param> 

public static void PostFormDataToGA(int visitorID, long timeStamp, string formName)
    {
        const string GA_TRACKING_ID = "UA-XXXXXXX-Y";

        Random randomNum = new Random();
        long timestampFirstRun, timestampLastRun, timestampCurrentRun, numberOfRuns;

        //timestamp to be set once per session. Else every subsequent form request will be counted as new user. 
        timestampFirstRun = timeStamp;
        timestampLastRun = timeStamp - 5;
        timestampCurrentRun = timeStamp;//45;

        numberOfRuns = 2;

        var domainName = Environment.UserDomainName;
        string domainHash = CreateDomainHash(domainName);
        string source = "ApplicationName"; //https://support.google.com/analytics/answer/1033173?hl=en
        string medium = "none"; //https://support.google.com/analytics/answer/1033173?hl=en
        string sessionNumber = "1";
        string campaignNumber = "1";
        string culture = Thread.CurrentThread.CurrentCulture.Name;

        string statsRequest = "http://www.google-analytics.com/__utm.gif" +
               "?utmwv=4.4" + //Tracking code version e.g. utmwv=1
               "&utmn="+ visitorID +  //+ randomNum.Next(100000000, 999999999) +  //Unique ID generated for each GIF request to prevent caching of the GIF image. e.g. utmn=1142651215
               "&utmcs=-" + //Language encoding for the browser. Some browsers don't set this, in which case it is set to "-"   utmcs=ISO-8859-1
               "&utmsc=-" + //Screen color depth    utmsc=24-bit
               "&utmul=" + culture + //Browser language.    utmul=pt-br
               "&utmje=-" + //Indicates if browser is Java-enabled. 1 is true.  utmje=1
               "&utmfl=-" + //Flash Version utmfl=9.0%20r48
               "&utmdt=" + formName + //Page title, which is a URL-encoded string.  utmdt=analytics%20page%20test
               "&utmhid=" + visitorID + //+ randomNum.Next(100000000, 999999999) + //1943799692" + //A random number used to link Analytics GIF requests with AdSense.  utmhid = 2059107202
               "&utmr=0" + //Referral, complete URL.    utmr=http://www.example.com/aboutUs/index.php?var=selected
               "&utmp=" + formName + //Page request of the current page.    utmp=/testDirectory/myPage.html
               "&utmac=" + GA_TRACKING_ID + //Account String.Appears on all requests.   utmac = UA - 2202604 - 2
               "&utmcc=" + //Cookie values. This request parameter sends all the cookies requested from the page.
                           //utmcc = __utma % 3D117243.1695285.22 % 3B % 2B __utmz% 3D117945243.1202416366.21.10.utmcsr % 3Db % 7C utmccn% 3D(referral) % 
                           //7C utmcmd% 3Dreferral % 7C utmcct% 3D % 252Fissue % 3B % 2B
               "__utma%3D" + domainHash + "." + visitorID + "." +
                   timestampFirstRun + "." + timestampLastRun + "." +
                   timestampCurrentRun + "." + numberOfRuns +
               "%3B%2B__utmz%3D" + domainHash + "." + timestampCurrentRun + "."
                   + sessionNumber + "." + campaignNumber + ".utmcsr%3D" +
                   source + "%7Cutmccn%3D(" + medium + ")%7Cutmcmd%3D" + medium +
              "%7Cutmcct%3D%2Fd31AaOM%3B";
        try
        {
            using (var client = new WebClient())
            {
                client.DownloadData(statsRequest);
            }
        }
        catch (Exception ex)
        {
            //Handle exception
        }
    }

static string CreateDomainHash(string d)
{
        int a = 1;
        int c = 0;
        int h;
        int o;
        if (!String.IsNullOrEmpty(d))
        {
            a = 0;
            for (h = d.Length - 1; h >= 0; h--)
            {
                o = d[h];
                a = (a << 6 & 268435455) + o + (o << 14);
                c = a & 266338304;
                a = c != 0 ? a ^ c >> 21 : a;
            }
        }
        return a.ToString();
    }



然后我发现了一些典型的问题:我的应用程序仅适用于Windows操作系统,但在GA它显示了应用程序是从Linux和Mac使用。这怎么可能。答案是:有时GA是垃圾邮件,因此显示不相关的数据。

Then I found some typical issue: My application is only for windows OS but in GA it shows the application is used from Linux and Mac. How is this possible. Answer to this is : sometime GA is hit by Spams hence showing irrelevant data

https://www.en.advertisercommunity.com/t5/Referral-垃圾邮件的流量/谷歌 - 分析 - 显示 - 错误的国家和操作系统/ TD-p / 507606#

http://help.analyticsedge.com/spam-filter/definitive -guide对去除 - 谷歌 - 分析垃圾邮件/

这篇关于是否有可能采用做为Gdata API C#发布windows窗体命中信息,以谷歌分析(轨道ID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆