CMS Development

WSalgado
Member

How to add a Facebook tracking script to CTA

Need help adding a FB script to a CTA on a form on a webpage. Can this be added in the module html?

4 Replies 4
AndyHoo
Participant

How to add a Facebook tracking script to CTA

Hi Alyssa, your answer seems to be exactly what I am  willing to do.

I need to track events on some Hubspot forms for my Facebook business manager. I have 2 scripts that I was told to "add to the form submission button" (because it is a pop up so there won't be a "thank you page" on which I can easily integrate that script.

 

Any detailed process on how and where to add this short script for my Hubspot form ?

0 Upvotes
alyssamwilie
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

How to add a Facebook tracking script to CTA

You can use the Hubspot form listeners to run the scripts on submission. Like so :

 

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
       YOUR SCRIPTS HERE
   }
});

 

 

If you want to ensure the scripts only run when that particular form is submitted (which I highly suggest) you can also look for the form ID with the listener:

 

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted' && event.data.id === 'FORM ID HERE') {
       YOUR SCRIPTS HERE
   }
});

 


 As to WHERE to add it there's a few options depending on your template set up. In order of most specific to most global :

  1. If the popup is a custom module you can add it to the Javascript section of the module
  2. If it's a HTML & HubL template you could just place it before the end </body> tag
  3. If it's a Drag and Drop template you can add it to the Additional <head> markup in the right hand sidebar, create a custom module to add it to and use, or add an HTML module to place it in
  4. You can add it to the Footer HTML in the page editor under the Settings Tab > Advanced Settings
  5. You can add it to Site Footer HTML under in portal Settings > Website > Pages

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
alyssamwilie
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

How to add a Facebook tracking script to CTA

By 'CTA on a form' do you mean the submit button? What exactly is the facebook script you're wanting to use? Cause you might could add a listener event to send the tracking information on submit of the form/click of a button.

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
webdew
Guide | Diamond Partner
Guide | Diamond Partner

How to add a Facebook tracking script to CTA

Hi @WSalgado ,

Unfortunately we cannot add script code in CTA.

Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.