# A/B Testing Hubspot Forms with Google Optimize

**URL:** <https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566>\
**Category:** Lead Capture Tools\
**Created:** [October 13, 2018, 12:46pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566 "2018-10-13T12:46:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nunoautotrip](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/nunoautotrip/32/76463_2.png) [@nunoautotrip](https://community.hubspot.com/u/nunoautotrip)\
**Post date:** [October 13, 2018, 12:46pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/1 "2018-10-13T12:46:03Z")

</div>

Hi everybody,

Has anyone tried to A/B test Hubspot forms by using Google Optimize?

If yes, what best practices would you recommend to follow?

I want to extensively A/B test my forms, but I don’t want to do it in a clunky way… it seems that I’d have to replace the entire HTML of the form if I want to test different variants.

This is where I’m testing a few changes now - [https://autotrip.com/buy-now/](https://autotrip.com/buy-now/)

 ![Screen Shot 2018-10-13 at 13.33.56.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/b/8/b85877e931a9adfdbb700211e24e9280e406b817.png)

 ![Screen Shot 2018-10-13 at 13.34.02.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/7/97a9c44f41162d0841f86955e282ae45487bf0b1.jpeg)

Thanks

---

<div class="post-metadata">

**Author:** ![Jenny](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jenny/32/24_2.png) [@Jenny](https://community.hubspot.com/u/Jenny)\
**Post date:** [October 16, 2018, 10:04am UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/2 "2018-10-16T10:04:16Z")

</div>

Hi @nunoautotrip,

While I haven’t expermimented with this myself, I did find a conversation about Google Optimize and forms on [Google’s forum](https://www.en.advertisercommunity.com/t5/Google-Optimize-Experiment/Is-it-possible-to-swap-forms-with-Google-Optimize/td-p/992426). It might be a good starting point for considering how to do this.

If you do try this out, let us know how it goes for you!

Thanks,  
Jenny

---

<div class="post-metadata">

**Author:** ![nunoautotrip](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/nunoautotrip/32/76463_2.png) [@nunoautotrip](https://community.hubspot.com/u/nunoautotrip)\
**Post date:** [October 16, 2018, 1:38pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/3 "2018-10-16T13:38:20Z")

</div>

Thanks, Jenny, I’ll try to do as they suggest.

---

<div class="post-metadata">

**Author:** ![jtron9k](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jtron9k/32/77566_2.png) [@jtron9k](https://community.hubspot.com/u/jtron9k)\
**Post date:** [January 8, 2019, 12:16am UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/4 "2019-01-08T00:16:55Z")

</div>

Did you have any luck?

---

<div class="post-metadata">

**Author:** ![Marijke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/marijke/32/64675_2.png) [@Marijke](https://community.hubspot.com/u/Marijke)\
**Post date:** [November 12, 2018, 3:36pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/5 "2018-11-12T15:36:04Z")

</div>

Hi,  
I’m trying to achieve the same thing and I think I just did by making a page with two forms, create two variants in Google Optimize, deleting one form on both variants and set the Weighting of visitors to target at 0% at the original page with two forms.  
I guess it will work, but I feel there could be a more efficient way? I think it should be able to just adjust the code to the right HS form, but when I open google optimize HTML editor the HubSpot form ‘ID’ doesn’t correspond with the actual HubSpot form ID which starts with: “a4200b83-\*\*\*\*-\*\*\*\*-\*\*\*\*-\*\*\*\*\*\*\*\*\*\*\*\*”

 ![google optimize.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/9/94763a6b7ef99e0f3824feefea84aa0c0e07fc5b.png)

Anyone tips on how to do this?

---

<div class="post-metadata">

**Author:** ![damianmakki](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/damianmakki/32/7476_2.png) [@damianmakki](https://community.hubspot.com/u/damianmakki)\
**Post date:** [February 20, 2020, 7:42pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/6 "2020-02-20T19:42:02Z")

</div>

Even though there’s an accepted solution here, I found a workaround to use the HubSpot embed forms within Google Optimize.

1. First you’ll need to load in the HubSpot form script using Optimize’s “Run JavaScript” option (just right click anywhere on the page):`// Create a script container then load in the URL.const hubSpotScript = document.createElement("script");hubSpotScript.src="https://js.hsforms.net/forms/v2.js";// Append it to the body to execute it.document.body.appendChild(hubSpotScript);`
2. Next you’ll need to create the form. I was only able to get this to fire by adding the window.addEventListener. You can grab your **portalId** and **formId** from the HubSpot form, itself – just hit “Share” or “Publish” and you can easily find it under the “Embed Code” tab.

```auto
window.addEventListener('load', function () {
 hbspt.forms.create({
 portalId: "yourPortalID",
 formId: "yourFormID", // You can target where you'd like the form to be injected. // https://developers.hubspot.com/docs/methods/forms/advanced_form_options
 target: '#yourElement',
 });
});

```

---

<div class="post-metadata">

**Author:** ![KabbeS](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@KabbeS](https://community.hubspot.com/u/KabbeS)\
**Post date:** [November 22, 2021, 3:09pm UTC](https://community.hubspot.com/t/a-b-testing-hubspot-forms-with-google-optimize/10566/7 "2021-11-22T15:09:31Z")

</div>

Interesting!  
Trying to do the same thing, but can’t seem to find a simpler solution. Have you found another solution only using form id?  
Thanks
