Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting Custom Dimension in Google Analytics with gtag set() Method

  • Troubleshooting Custom Dimension in Google Analytics with gtag set() Method

    Posted by Liam on 11 July 2022 at 10:35 pm

    Hey there, I need a little help with setting up a custom dimension for GA4. I named it chain_id and tried to integrate it using the gtag set method. Just to be safe, I added the custom_map property into the config as well (even though I am not 100% certain if that’s necessary).

    I noticed the issue, seems like the chain_id is not sent with the event. I spot-checked this with the GA debugger’s console output. I was expecting the chain_id with the value of Test chain id to show up under event parameters, but it’s missing. Any thoughts on this?

    Check the debugger console snapshot here: snapshot

    Here’s the JavaScript and HTML code I’m working with:

    Cheers!

    Elijah replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • George

    Member
    14 August 2022 at 6:43 am

    Sure, here’s the gist of the situation:

    The gtag set method doesn’t function as you might expect. It’s primarily useful for altering the DL for GTM’s benefit, but it doesn’t do much for setting properties. Nevertheless, you have alternatives.

    One method is to define the params directly within the event call, like this: gtag("event", "Button click", {chain_id: "test id"});.

    Please see this console snapshot for reference: [Console_Snapshot](https://i.stack.imgur.com/H2vhw.png)

    Another method is to set the eps through the config, which will make them persist. See this snapshot for reference: [Event Snapshot](https://i.stack.imgur.com/8rt2o.png). However, please take note that Google recently updated for ignoring configs issued after the initial config. So, if you aim to modify persistent event parameters for all following events by issuing a config and gtag.js just disregards it, you might want to check out this discussion: [GA4_custom_dimensions_discussion](https://stackoverflow.com/questions/76177242/can-ga4-custom-dimensions-be-updated-after-the-initial-config-call/76222825#76222825)

    In conclusion, I highly recommend you to consider using Google Tag Manager (GTM) or any other TMS. It simplifies the process of implementing, managing, scaling, and supporting tracking. Using gtag.js for tracking is practical when your tracking needs are minimal and it doesn’t affect your long-term business results.

  • Elijah

    Member
    11 March 2023 at 2:45 am

    Based on the information you’ve provided, it seems like the set function may not be effectively transmitting the chain_id with your events. To troubleshoot the issue, you could try using Google Tag Manager’s Field To Set feature to set the chain_id for your GA4 configuration. This would equate to calling gtag('config','{Your GA4 ID}', { 'chain_id': 'Test chain id' }); in your code. Then, when calling the event in your code, try something like this: gtag('event','click', { 'send_to': '{Your GA4 ID}' });. This might help ensure that the chain_id is consistently being sent with your events. Do note, however, that you’d need to replace {Your GA4 ID} with your actual Google Analytics 4 ID in the above examples.

Log in to reply.