从服务器端以编程方式发送 Google Analytics 事件不起作用

我们想从服务器端向谷歌分析发送自定义事件跟踪信息。


为此,我参考了这篇SO post,并提出了以下代码片段,但不知何故它没有将事件的信息发送到 GA。我调试了代码以查看响应,它返回200 (OK)状态,响应类似于通过客户端跟踪事件时的响应。我们已经等了几天,看看事件是否被跟踪,但它没有。


    public static void TrackEvent(string category, string action, string label)

    {

        string gaCodeTest = "UA-xxxxxx-2";

        ASCIIEncoding encoding = new ASCIIEncoding();

        string cid = Guid.NewGuid().ToString();


        string postData =

            "v=1&tid=" + gaCodeTest + " &cid=" + cid + "&t=event" +

            "&ec=" + category +

            "&ea=" + action +

            "&el=" + label;


        byte[] data = encoding.GetBytes(postData);

        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.google-analytics.com/collect");


        myRequest.Method = "POST";

        myRequest.ContentType = "application/x-www-form-urlencoded";

        myRequest.ContentLength = data.Length;

        Stream newStream = myRequest.GetRequestStream();

        newStream.Write(data, 0, data.Length);


        var response = (HttpWebResponse)myRequest.GetResponse();


        //var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();


        newStream.Close();


    }


HUH函数
浏览 215回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP