0
votes

We are sending the purchase events from the server with code like this:

using (var httpClient = new RestClient())
            {
                httpClient.SendAsync(new HttpRequestMessage
                {
                    RequestUri = new Uri(url),
                    Method = HttpMethod.Get
                });
           }

But around 15-20% of the events never gets registered in GA. Google always seem to respond with a GIF and status code 200, so it is hard to tell which events are not processed successfully.

In the beginning we were using the javascript API to send the event, but when we switched to server side, we copied the request it was creating and tried to replicate it with HttpClient.

The request send looks like the following:

https://www.google-analytics.com/collect?v=1&_v=j47&a=817546713&t=event&ni=0&_s=1& dl=#scheme + host + pathAndQuery#&dp=#path#&dt=#path#&ul=#browser language#&de=#browser encoding#&sd=#bit#&sr=#screen resolution#&vp=#viewable browser area#&cid=#Id taken from the _ga cookie#&je=0&fl=24.0%20r0&ec=Ecommerce&ea=purchase &_u=SCEAAAALI20%25~&jid=&tid=#TrackingId#&gtm=#TagManagerId#&ti=#OrderId#&ta=& tr=#TotalPrice#&tt=#TotalTax#&ts=#ShippingPrice#&tcc=#VoucherCode# &pa=purchase&cu=#CurrencyCode#&pr1nm=#ProducteName#&pr1id=#ProductId#&pr1pr=#ProductPrice#&pr1br=#Brand#&pr1ca=&pr1va=#Variant#&pr1qt=#Quantity#&z=#Randomly generated unique id#

Any ideas about what is wrong or how to debug it is welcome

1
Creative approach. Any reason why you're not pushing the event and its payload into the dataLayer that GTM uses?Iskandar Reza

1 Answers

0
votes

You shouldn't do that on the backend. The correct way is to do that on the frontend

The easiest and the correct way is to send data to your dataLayer and then in GTM send an event to GA.

P.S. In your C# code I can see the problem that you are not awaiting async method. If your method is not async, then you can use it like that:

var temp = httpClient.SendAsync(new HttpRequestMessage
            {
                RequestUri = new Uri(url),
                Method = HttpMethod.Get
            }).Result;