Run Google Ad conversion tag on signup, ReactJS
Google says this should be added to html on the "conversion page".
<!-- Event snippet for Website lead conversion page --> <script>gtag('event', 'conversion', {'send_to': 'AW-sdad/-dsafdsa'});</script>
I have a ReactJS app, so I have no single html "conversion page".
Can I run it from javascript somehow?
createAccount = () => { Axios.post(`/api/signup`, { user }) .then(async (resp) => { await Axios.post("/api/login", { email: this.state.email, password: this.state.password }); this.props.history.push("/app"); // Run google ad convert here? }) .catch((err) => { console.log(err); }); };
Use React Helmet. It basically helps you to change something inside <head> or <body> So you just need to add that piece of code inside your component responsible for your conversion page.
const SignUpPage = () => { return ( <div> <Helmet> <!-- Event snippet for Website lead conversion page --> <script>gtag('event', 'conversion', {'send_to': 'AW-sdad/-dsafdsa'});</script> </Helmet> SignIn page here </div> ); };@SergeyNikolayevich please elaborate. There might be numerous reasons why it is not working for you. Have you read React helmet documentation? Do you fully understand how it works?
@Arseniy-II, here is the solution which worked for me. Obviously, I found Arseniy's code helpful for me and I added some quotation marks around gtag
<Helmet> <script>{`{"gtag('event', 'conversion', {'send_to': 'AW-xxx/xxx'});"}`}</script> </Helmet>