google-analytics - 如何以编程方式在谷歌分析中插入数据

标签 google-analytics google-analytics-firebase google-analytics-sdk

您能告诉我以下以编程方式在 Google Analytics 中插入综合浏览量的代码有什么问题吗?

代码未插入综合浏览量。

var request = (HttpWebRequest)WebRequest.Create("http://www.google-analytics.com");
            request.Method = "POST";

            // the request body we want to send
            var postData = new Dictionary<string, string>
{
{ "v", "1" },
{ "tid", "UA-XXXXXX-1" },
{ "cid", "555" },
{ "t", "pageview" },
{"dh","www.pomroofing.com"},
{ "dp", "/phone/123/456/789/1" },
{ "dt", "homepage" },
};


            var postDataString = postData
            .Aggregate("", (data, next) => string.Format("{0}&{1}={2}", data, next.Key,
            HttpUtility.UrlEncode(next.Value)))
            .TrimEnd('&');

            // set the Content-Length header to the correct value
            request.ContentLength = Encoding.UTF8.GetByteCount(postDataString);

            // write the request body to the request
            using (var writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(postDataString);
            }

            try
            {
                var webResponse = (HttpWebResponse)request.GetResponse();
                if (webResponse.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpException((int)webResponse.StatusCode,
                    "Google Analytics tracking did not return OK 200");
                }
            }
            catch (Exception ex)
            {
                // do what you like here, we log to Elmah
                // ElmahLog.LogError(ex, "Google Analytics tracking failed");
            }

请帮忙,或者有没有相关的API。

最佳答案

尝试直接在浏览器中测试完整的请求字符串。像这样的简短请求也可以使用 GET 发送。

检查实时报告以查看其是否显示。 (我测试过这个)

http://www.google-analytics.com/collect?v=1&tid=UA-XXXX-X&cid=555&t=pageview&dh=www.pomroofing.com&dp=/phone/123/456/789/1&dt=homepage

不,没有用于此目的的 API。

顺便说一句,您的网址中缺少/collect :)

关于google-analytics - 如何以编程方式在谷歌分析中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28758024/

相关文章:

Android Google Analytics 不报告未捕获的崩溃和异常

android - 使用 Google Play 服务手动刷新 google 分析事件

android - 使用 GoogleAnalytics 忽略多个安装 Activity 时出错

javascript - 带有 Tumblr 分享按钮的 Google 社交互动分析?

javascript - 仅使用 API key 访问 Google Analytics 数据

google-analytics - 如何使用 Google Analytics SDK 返回总浏览量?

ios - Cocoapods更新GoogleAnalytics sdk返回SSL证书错误

ios - 无法将没有 cocoa pod 的 Google Analytics iOS SDK 添加到我的项目中

Android Phonegap 插件和谷歌分析

java - Eclipse 在导入中未检测到 Google Analytics V4