简体   繁体   中英

How can I add an event for the Facebook Pixel to a button in my site in React?

I would like the pixel to register a click on a button as a 'lead' in the Events Manager.
I can only add this event by doing something in the code, inside React. I cannot use the 'Event Setup Tool'.
The pixel is setup in my React site inside the 'index.html' file and only registers site visits.
The instructions on Facebook's developer website seem to only be for html with non-React style Javascript.

This is what I tried.

<a href="/#"><input className="subm_button" onClick="fbq('track', 'Lead');" type="submit" value="Submit"/></a>

My form is inside a component imported into another page, so I'm not sure if 'fbq' has to be imported somewhere either in the component or in the page. Like I said, I've always put the Pixel in the index.html and don't know how to deal with it anywhere else in React.

I cannot use the 'Event Setup Tool' because my client didn't add me as an admin, but there is a working pixel live on the site.

you can access window variables via window reference

<a href="/#"><input className="subm_button" onClick={e => window.fbq('track', 'Lead');} type="submit" value="Submit"/></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM