How should I implement this script in my HubSpot form to push the GA client ID into a hidden field?



Hi community,

I would like to get a functionality set up on my form where it pushes the GA client ID from the GA cookie into a hidden field in the HubSpot form with a script of Java (Jquery). I did some research and found a site that explained how it is possible here.

The script that I took from there is:

$("#form-id").submit(function() {
ga(function() {
var clientId = ga.getAll()[3].get(‘clientId’);

The trouble that I am having is that I’m not sure what exactly the variables are within the script and what they should be changed to to get the function working on my specific form. It also does not explain where the script should go. Would it go in the header of the page or in the embed code of the form.

I’m sorry if it seems like a dumb question, I’m not too experienced with this.