I just installed the gatsby-plugin-google-gtag
in my gatsby-config.js
file:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-google-gtag`,
options: {
trackingIds: [
"UA-XXXXXXXXX-X", // Google Analytics / GA
"AW-XXXXXXXXX" // Google Ads / Adwords / AW
],
pluginConfig: {
head: true
},
}
}
]
}
I then add this event on my form, is it supposed to work?
class Form extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
window.gtag("conversion", "click", { send_to: ["AW-XXXXXXXXX/-XXXXXXXXXXXXXXXX"]})
}
render() {
return (
<Div className='au'>
<form action="https://formspree.io/my@emailaddress.io" method="POST">
<InputName type="name" name="name" placeholder="Your Name"/>
<InputMail type="email" name="email" placeholder="Your Mail"/>
<Button type="submit" onClick={this.handleClick}>Contact us</Button>
</form>
</Div>
)
}
}
export default Form;
from the docs:
This plugin only works in production mode!
Also your config looks good, just make sure your trackingIds are correct
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With