谷歌分析产品的代码在 c# 中命中

本文关键字:代码 谷歌 | 更新日期: 2023-09-27 17:56:04

我是谷歌分析的新手。关于这一点,我经历了一些。我发现在谷歌分析中没有直接的方法可以击中Windows应用程序。但我在stackoverflow中找到了一些解决方案。我试过了,但对我不起作用。下面是我正在使用的代码。

私有无效分析方法4(字符串跟踪ID,字符串页面名称) { 随机 rnd = 新的随机();

        long timestampFirstRun, timestampLastRun, timestampCurrentRun, numberOfRuns;
        // Get the first run time
        timestampFirstRun = DateTime.Now.Ticks;
        timestampLastRun = DateTime.Now.Ticks - 5;
        timestampCurrentRun = 45;
        numberOfRuns = 2;
        // Some values we need
        string domainHash = "123456789"; // This can be calcualted for your domain online
        int uniqueVisitorId = rnd.Next(100000000, 999999999); // Random
        string source = "Shop";
        string medium = "medium123";
        string sessionNumber = "1";
        string campaignNumber = "1";
        string culture = Thread.CurrentThread.CurrentCulture.Name;
        string screenRes = Screen.PrimaryScreen.Bounds.Width + "x" + Screen.PrimaryScreen.Bounds.Height;
        string statsRequest = "http://www.google-analytics.com/__utm.gif" +
            "?utmwv=4.6.5" +
            "&utmn=" + rnd.Next(100000000, 999999999) +
            //  "&utmhn=hostname.mydomain.com" +
            "&utmcs=-" +
            "&utmsr=" + screenRes +
            "&utmsc=-" +
            "&utmul=" + culture +
            "&utmje=-" +
            "&utmfl=-" +
            "&utmdt=" + pagename + // Here i passed my profile name "MyWindowsApp"
            "&utmhid=1943799692" +
            "&utmr=0" +
            "&utmp=" + pagename +
            "&utmac=" + trackingId + //Tracking id : ie "UA-XXXXXXXX-X"
            "&utmcc=" +
                "__utma%3D" + domainHash + "." + uniqueVisitorId + "." + 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())
            {
                //byte[] bt = client.DownloadData(statsRequest);
                Stream data = client.OpenRead(statsRequest);
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
                MessageBox.Show(s);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

这个例子也是从这个网站本身获得的。我不知道问题出在哪里。请指导我,我该怎么做。这是我得到的输出"GIF89a"。

谢谢线轴保洛糖

谷歌分析产品的代码在 c# 中命中

所以它正在工作。Google Analytics调用加载一个微小的GIF图像,请求中提供的查询字符串参数会触发所有Google Analytics的优点。如果您收到回复,则表示您已成功向 Google 注册活动。