APIs & Integrations

zohaib
Member

Hubspot event send to google Analytics

SOLVE

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

0 Upvotes
1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubspot event send to google Analytics

SOLVE

Thanks for jumping in, @WendyGoh Smiley Happy

 

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

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
5 Replies 5
ralphioooo
Contributor | Diamond Partner
Contributor | Diamond Partner

Hubspot event send to google Analytics

SOLVE


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:
https://ecosystem.hubspot.com/marketplace/apps/marketing/analytics-data/google-analytics-amplifier-2...

0 Upvotes
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubspot event send to google Analytics

SOLVE

Thanks for jumping in, @WendyGoh Smiley Happy

 

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

Isaac Takushi

Associate Certification Manager
0 Upvotes
WendyGoh
HubSpot Employee
HubSpot Employee

Hubspot event send to google Analytics

SOLVE

Hi @zohaib ,

 

While I'm not Isaac, let me help you out here 🙂 

 

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? 🙂

zohaib
Member

Hubspot event send to google Analytics

SOLVE

@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

0 Upvotes
WendyGoh
HubSpot Employee
HubSpot Employee

Hubspot event send to google Analytics

SOLVE

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 BasicProfessional, or Enterprise, you can refer to this documentation here - on how to unstyled a HubSpot form.

0 Upvotes