<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: GA4 client ID on hidden form block in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1168275#M82797</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/945160"&gt;@BrandonWoodruff&lt;/a&gt;&amp;nbsp;it because form embed uses iframe so injecting doesnt work?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jun 2025 11:40:44 GMT</pubDate>
    <dc:creator>VB47</dc:creator>
    <dc:date>2025-06-26T11:40:44Z</dc:date>
    <item>
      <title>GA4 client ID on hidden form block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1167825#M82775</link>
      <description>&lt;P&gt;Hi, I am using GTM and GA4 on my website to gather analytics data. I have embedded a hubspot form that i created a hidden block on labeled 'GA Client ID' (internal name is ga_client_id) in hopes that a GTM/javascript setup will be able to inject the client id data into that block so when someone submits the form their client id is carried over into hubspot too. currently i am using a custom html tag in GTM that fires after my config tag triggered on all pages. The tag is firing fine but the data is not being injected and im getting a 403 error on the form too. Here is the script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;function injectGAClientId() {&lt;BR /&gt;if (typeof gtag !== 'function') {&lt;BR /&gt;// Retry after 300ms if gtag isn't ready&lt;BR /&gt;setTimeout(injectGAClientId, 300);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;gtag('get', 'G-KDPBR8EQT4', 'client_id', function(clientId) {&lt;BR /&gt;if (!clientId) {&lt;BR /&gt;setTimeout(injectGAClientId, 300);&lt;BR /&gt;return;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var attempts = 0;&lt;BR /&gt;var interval = setInterval(function() {&lt;BR /&gt;var inputs = document.querySelectorAll('input[name$="ga_client_id"]');&lt;BR /&gt;if (inputs.length &amp;gt; 0) {&lt;BR /&gt;inputs.forEach(function(input) {&lt;BR /&gt;input.value = clientId;&lt;BR /&gt;});&lt;BR /&gt;clearInterval(interval);&lt;BR /&gt;console.log('Injected GA Client ID:', clientId);&lt;BR /&gt;}&lt;BR /&gt;attempts++;&lt;BR /&gt;if (attempts &amp;gt; 20) clearInterval(interval);&lt;BR /&gt;}, 300);&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;window.addEventListener('load', injectGAClientId);&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my embedded code on my websites elementor html block is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;script charset="utf-8" type="text/javascript" src="//js-na2.hsforms.net/forms/v2.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;script&amp;gt;&lt;BR /&gt;function getGA4ClientId() {&lt;BR /&gt;const cookieValue = document.cookie.split('; ').find(row =&amp;gt; row.startsWith('_ga='));&lt;BR /&gt;return cookieValue ? cookieValue.split('=')[1].split('.').slice(-2).join('.') : 'not_set';&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;hbspt.forms.create({&lt;BR /&gt;region: "na2",&lt;BR /&gt;portalId: "243078151",&lt;BR /&gt;formId: "29239f66-0317-4f23-9fb5-879021dd5bca",&lt;BR /&gt;target: "#hubspot-form-container",&lt;BR /&gt;onFormReady: function(form) {&lt;BR /&gt;var clientId = getGA4ClientId();&lt;BR /&gt;var hiddenField = document.querySelector('input[name="ga_client_id"]');&lt;BR /&gt;if (hiddenField) {&lt;BR /&gt;hiddenField.value = clientId;&lt;BR /&gt;console.log("Set GA client ID:", clientId);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;});&lt;BR /&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;div id="hubspot-form-container"&amp;gt;&amp;lt;/div&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've looked high and low for a solution and this forum is my last resort, hoping someone can help, ty.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2025 08:20:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1167825#M82775</guid>
      <dc:creator>VB47</dc:creator>
      <dc:date>2025-06-23T08:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: GA4 client ID on hidden form block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1167993#M82781</link>
      <description>&lt;P&gt;Hello! Here are some things I would try testing out:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Double check the form values&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;What to verify Why it matters Where to fix &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Contact property exists &amp;amp; is allowed in forms&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;A field won’t render (even hidden) unless the underlying property’s &lt;EM&gt;Show in forms, pop-up forms, and bots&lt;/EM&gt; option is on&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;Settings → Properties → ga_client_id&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Field is &lt;EM&gt;not&lt;/EM&gt; marked “Required”&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;Required fields can’t be hidden; HubSpot blocks the form and returns a 403-style error&lt;/TD&gt;&lt;TD&gt;In the form editor&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;It really is on the live form&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;Progressive / conditional logic can hide a field you thought was there&lt;/TD&gt;&lt;TD&gt;Test on the form’s standalone URL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;Quick test:&lt;/STRONG&gt; open the form’s standalone link, inspect element, and confirm you see&lt;BR /&gt;&amp;lt;input name="ga_client_id" type="hidden"&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;2. Try sending the value using v4 HubSpot APIs&lt;/P&gt;&lt;P&gt;The embed script already gives you two hooks:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;hbspt.&lt;SPAN class=""&gt;forms&lt;/SPAN&gt;.&lt;SPAN class=""&gt;create&lt;/SPAN&gt;({ &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;portalId&lt;/SPAN&gt;: &lt;SPAN class=""&gt;'243078151'&lt;/SPAN&gt;, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;formId : &lt;SPAN class=""&gt;'29239f66-0317-4f23-9fb5-879021dd5bca'&lt;/SPAN&gt;, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;target : &lt;SPAN class=""&gt;'#hubspot-form-container'&lt;/SPAN&gt;, &lt;SPAN class=""&gt;/* fires once the form markup is in the DOM */&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;onFormReady&lt;/SPAN&gt;: &lt;SPAN class=""&gt;function&lt;/SPAN&gt;(&lt;SPAN class=""&gt;form&lt;/SPAN&gt;) { &lt;SPAN class=""&gt;pushGAClientId&lt;/SPAN&gt;(form); &lt;SPAN class=""&gt;// set default so the visitor sees the right value&lt;/SPAN&gt; }, &lt;SPAN class=""&gt;/* fires *just before* HubSpot packages the payload */&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;onBeforeFormSubmit&lt;/SPAN&gt;: &lt;SPAN class=""&gt;function&lt;/SPAN&gt;(&lt;SPAN class=""&gt;form&lt;/SPAN&gt;) { &lt;SPAN class=""&gt;pushGAClientId&lt;/SPAN&gt;(form); &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;// guarantees latest value right before submit&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;} }); &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;function&lt;/SPAN&gt; &lt;SPAN class=""&gt;pushGAClientId&lt;/SPAN&gt;(&lt;SPAN class=""&gt;form&lt;/SPAN&gt;){ &lt;SPAN class=""&gt;const&lt;/SPAN&gt; cid = &lt;SPAN class=""&gt;getGA4ClientId&lt;/SPAN&gt;(); &lt;SPAN class=""&gt;// your cookie-parsing helper&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt;(!cid) { &lt;SPAN class=""&gt;return&lt;/SPAN&gt;; } &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;/* safest method: HubSpot Forms v4 API */&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt;(&lt;SPAN class=""&gt;window&lt;/SPAN&gt;.&lt;SPAN class=""&gt;HubspotFormsV4&lt;/SPAN&gt;){ &lt;SPAN class=""&gt;HubspotFormsV4&lt;/SPAN&gt;.&lt;SPAN class=""&gt;getFormFromEvent&lt;/SPAN&gt; &amp;amp;&amp;amp; &lt;SPAN class=""&gt;HubspotFormsV4&lt;/SPAN&gt;.&lt;SPAN class=""&gt;getFormFromEvent&lt;/SPAN&gt;({&lt;SPAN class=""&gt;target&lt;/SPAN&gt;:form}) .&lt;SPAN class=""&gt;setFieldValue&lt;/SPAN&gt;(&lt;SPAN class=""&gt;'ga_client_id'&lt;/SPAN&gt;, cid); &lt;SPAN class=""&gt;// programmatic set&lt;/SPAN&gt; }&lt;SPAN class=""&gt;else&lt;/SPAN&gt;{ &lt;SPAN class=""&gt;/* fallback: vanilla DOM + synthetic change event */&lt;/SPAN&gt; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; input = form.&lt;SPAN class=""&gt;querySelector&lt;/SPAN&gt;(&lt;SPAN class=""&gt;'input[name="ga_client_id"]'&lt;/SPAN&gt;); &lt;SPAN class=""&gt;if&lt;/SPAN&gt;(input){ input.&lt;SPAN class=""&gt;value&lt;/SPAN&gt; = cid; &lt;SPAN class=""&gt;/* tell HubSpot the field really changed */&lt;/SPAN&gt; input.&lt;SPAN class=""&gt;dispatchEvent&lt;/SPAN&gt;(&lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;Event&lt;/SPAN&gt;(&lt;SPAN class=""&gt;'input'&lt;/SPAN&gt;, {&lt;SPAN class=""&gt;bubbles&lt;/SPAN&gt;:&lt;SPAN class=""&gt;true&lt;/SPAN&gt;})); &lt;SPAN class=""&gt;// HubSpot listens for this&lt;/SPAN&gt; } } }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;STRONG&gt;Why this version works better&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Runs twice&lt;/STRONG&gt; – once when the form hits the page, again right before submission, so late-loading cookies don’t get missed.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Uses HubSpot’s own API&lt;/STRONG&gt; so the value is guaranteed to persist even if the DOM is re-rendered.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Fires a proper input event&lt;/STRONG&gt; when you fall back to direct DOM editing (HubSpot looks for it).&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;3. Figuring out the 403 error.&lt;/P&gt;&lt;P&gt;A 403 from the forms endpoint usually means something is blocking the request &lt;STRONG&gt;before&lt;/STRONG&gt; it ever gets to GA code:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Likely cause Quick diagnostic Fix &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Script conflict / altered embed code&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;Compare your page source vs. the official embed in &lt;EM&gt;Marketing → Forms → Share → Get Embed Code&lt;/EM&gt; (DiffChecker tip from HubSpot docs)&lt;/TD&gt;&lt;TD&gt;Re-paste the untouched embed snippet&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Hidden “required” field or missing email&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;Submit the form’s &lt;EM&gt;stand-alone URL&lt;/EM&gt; in a clean browser profile. If it works there, the page or a hidden field is the culprit (general troubleshooting flow)&lt;/TD&gt;&lt;TD&gt;Remove the requirement or expose the field&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Region mismatch&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;js-na2.hsforms.net ↔ region:"na2" is correct. If you ever switch to the default host (js.hsforms.net) make sure region is na1.&lt;/TD&gt;&lt;TD&gt;Keep region &amp;amp; script host in sync&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;4. Testing it out&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Open the form’s standalone link in an &lt;STRONG&gt;incognito&lt;/STRONG&gt; window.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Pop open DevTools → Network tab, filter for submit-form.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Submit once and verify you see ga_client_id=&amp;lt;value&amp;gt; in the payload and a 204 No Content response (success).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;If you still see 403, temporarily &lt;STRONG&gt;remove&lt;/STRONG&gt; all custom GTM tags, retest, and add back one by one.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;P&gt;Once the hidden property is legit, the field isn’t secretly “required,” and the value is set via the API (or dispatched input event), that GA4 client ID should glide straight into the contact record on every submission.&lt;/P&gt;&lt;P&gt;Holler if anything still misbehaves — happy to dig deeper. Good luck! &lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2025 13:19:01 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1167993#M82781</guid>
      <dc:creator>BrandonWoodruff</dc:creator>
      <dc:date>2025-06-23T13:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: GA4 client ID on hidden form block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1168243#M82795</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;form values are fine&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. can you provide full code for both - what should be in my GTM tag custom HTML and what should be in my sites elementor HTML? I've tried everything and still nothing.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;TY&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2025 21:32:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1168243#M82795</guid>
      <dc:creator>VB47</dc:creator>
      <dc:date>2025-06-23T21:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: GA4 client ID on hidden form block</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1168275#M82797</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/945160"&gt;@BrandonWoodruff&lt;/a&gt;&amp;nbsp;it because form embed uses iframe so injecting doesnt work?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jun 2025 11:40:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/GA4-client-ID-on-hidden-form-block/m-p/1168275#M82797</guid>
      <dc:creator>VB47</dc:creator>
      <dc:date>2025-06-26T11:40:44Z</dc:date>
    </item>
  </channel>
</rss>

