1

I run a small webapp. The app is hosted on app.mydomain.com and my 'main' website is just on mydomain.com. On my main website I installed Google Tag Manager and installed/linked a GA4 property. On the subdomain I just directly pasted the tracking code in the <head> of the same GA4 property as on my main website as this article suggests. So both the subdomain and the main site use the same tracking code.

The problem is that all my conversions are marked as 'direct'. I know that this can't be true, because 99% of my traffic comes from Google Search and I just started with Google Ads. So I would expect to see all my conversions being marked with Google search or Paid:

enter image description here

The Traffic acquisition does show multiple traffic sources:

enter image description here

The only thing I can think of, is that I track my conversions probably a bit different than most people. Once a payment is made, my server sends a request to Google Analytics to generate a conversion event:

exports.generateGA4Conversion = async () => {
  const measurement_id = process.env.MEASUREMENT_ID;
  const api_secret = process.env.GA4_API_SECRET;

  fetch(
    `https://www.google-analytics.com/mp/collect?measurement_id=${measurement_id}&api_secret=${api_secret}`,
    {
      method: "POST",
      headers: {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        client_id: "123",
        events: [
          {
            name: "conversion",
            params: { succes: true },
          },
        ],
      }),
    }
  );
};

Could that be the culprit?

0

1 Answer 1

1

Yes, your custom script is the "culprit". It happens in this section:

 headers: {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
        "Content-Type": "application/json",
      },

You are sending a custom set of headers, basically User Agent and Content-Type. If you want to identify the Direct traffic, you need to add the Referer header with the relevant information.

2
  • How would I do that? Could you provide an example? The code I used came directly from the Google docs...
    – Reinier68
    Jan 24 at 6:10
  • I haven't tested it, but you could try adding after: "Content-Type": "application/json", the following: "Referer": Document.referrer, Jan 25 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.