0

我是谷歌分析的新手。我对此进行了一些讨论。我发现在谷歌分析中没有直接的方法来点击 Windows 应用程序。但是我在stackoverflow中找到了一些解决方案。我试过了,但没有为我工作。下面是我正在使用的代码。

private void analyticsmethod4(string trackingId, string pagename) { Random rnd = new Random();

        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”的输出。

谢谢波宾·保罗斯

4

1 回答 1

0

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

于 2013-01-24T14:35:59.870 回答