Learn business growth with Google Analytics 4 Forums Google Analytics 4 Converting a GA4 Event's float parameter to a STRING value for sending

  • Converting a GA4 Event's float parameter to a STRING value for sending

    Posted by Harry on 11 April 2023 at 7:18 am

    Hey there! I’m having a little problem with Google Tag Manager’s GA4 Event’s User Properties, and I was wondering if you could help me out. I’m trying to send over the user’s client ID to GA4 – it’s usually a 20-digit number separated by a ‘.’.

    The kicker is, when it reaches GA4, the Client ID parameter is read as a float number (courtesy of its format, something like ‘1.5437e+09’ you know), and it gets rounded up, or worse, loses a few digit at the end.

    I tried adding a letter to the parameter, kind of like “S_{{client_id}}”, and it works alright. But it just doesn’t feel quite right, you get me? I want to find a cleaner way to do this. I even tried to convert the client ID specifically to string, using the JS .toString() method, but GA4 is still stuck on reading it as a float number.

    So here’s my question for you – how can I set a parameter’s type on GTM to be sent over specifically as a STRING, no matter if it looks like a float number?

    Emily replied 10 months, 3 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Aaron

    27 May 2023 at 5:15 pm

    Hey there! It seems like you’ve stumbled upon one of those tricky things with Google. They’ve designed it to automatically interpret numbers as numerical values, not strings, even if you’ve tried converting them with something like the .toString() method.

    A workaround that’s been found, which is a bit subtler than adding a letter to the ID, is to just stick a ‘.’ at the end of your value. This forces Google to acknowledge it as a string, and not a number. So, instead of just {{client_id}}, you’ll be using {{client_id}}.

    Sure, it may not be the perfect solution, but it’s a pretty nifty way to make sure Google treats those IDs right!

  • Emily

    28 May 2023 at 6:26 am

    The solution to this is actually quite simple! You can wrap your client ID in what’s known as a ‘zero width space’ character before you send it over to GA4. This special character (which is ‘& #8203;’ without the spaces) effectively convinces GA4 to treat the enclosed value as a string, even if it looks like a floating-point number. After you’ve wrapped up your client ID like this, it should show up in BigQuery as a string just as planned!

Log in to reply.