Hubspot event send to google Analytics

Hi @IsaacTakushi dear i am facing another problem in hubspot.How to send Events from hubspot to Google Analytics.. I want to set Form field if google analytics cookie is set.I embeded js code on form and add that form on landing page but it does not set form field(google_client_id) when i fill the form on landing page..can you solve this problem.please review my code.

In all Hubspot forms add “GA Client id” as an optional hidden field
Modify the script tag on all Hubspot forms to set ga_client_id if the GA cookie is set

<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/v2.js”></script>
<script>
function setGaClientId() {
if ($(‘[name=ga_client_id]’)[0]) {
$(‘[name=ga_client_id]’).val(_((Cookies.get(‘_ga’) || ‘’).split(‘.’)).takeRight(2).join(‘.’));
}
}
hbspt.forms.create({
css: ‘’,
portalId: ‘’,
formId: ‘’,
onFormSubmit: setGaClientId
});
</script>

..Thank you

Hi @zohaib ,

While I’m not Isaac, let me help you out here :slightly_smiling_face:

I understand that you’re looking to send events from HubSpot to Google Analytics by maniuplating the jQuery and it seems that it is currently not working.

On my end, I tried testing out the code that you provided using a string field and it looks like all is working. Narrowing down to the if condition, it also seems that, there wouldn’t be an issue.

Hence, I believe the issue here is likely due to this line of code:

$(‘[name=ga_client_id]’).val(_((Cookies.get(‘_ga’) || ‘’).split(‘.’)).takeRight(2).join(‘.’));

Are we able to further check if a value is being returning from this line of code?

Additionally, do you mind sharing with me an example page that has the form embed on it? :slightly_smiling_face:

@WendyGoh can i add a javascript functions on Forms and on Landing Pages..if yes then please tell me how to add javascript code on forms and landing pages…

Thanks

Hi @zohaib,

As per what @IsaacTakushi mentioned here: Send event from hubspot to google analytics also set form field when google anlaytics cookie is set

“Marketing Free and Starter forms are rendered in an iframe through js.hsforms.net/forms/shell.js instead of js.hsforms.net/forms/v2.js, so they cannot be manipulated with jQuery or styled with on-page CSS.”

If your team subscription is any of Marketing Basic, Professional, or Enterprise, you can refer to this documentation here - on how to unstyled a HubSpot form.

Thanks for jumping in, @WendyGoh
16x16_smiley-happy.png.png

@zohaib, yesterday, I responded to your thread from last week. Please do not post the same question twice.

We have just created a HubSpot APP called Analytics Amplifier that helps you do this + push offline events to Google Analytics when they happen.

Check it out here: