Manually sending data to Google Analytics

前端 未结 6 1296
北荒
北荒 2020-12-28 19:49

I was wondering if I can send google analytics tracking data to google by sending custom URL requests. I assumed I could build my own URLs and fire a request to get events t

6条回答
  •  感情败类
    2020-12-28 20:21

    In addition to @pavel-morshenyuk answer, if you want to correlate the event to the user who actioned on it, the code below will map the request to the google client id.

     string clientId = Guid.NewGuid().ToString();
    
     if (Request != null && Request.Cookies != null && Request.Cookies.Get("_ga") != null && Request.Cookies.Get("_ga").Value != null)
     {
        clientId = Request.Cookies.Get("_ga").Value;
        clientId = clientId.Replace("GA1.2.", "");
        clientId = clientId.Replace("GA1.1.", "");
     }
    

    note at some point, this may need to be tweaked if GA changes their internal cookie tracking.

提交回复
热议问题