Archived topic
Add conversion tracking code to a button image
3 replies · Started by Brian on March 26, 2021
I have a gif (buy from amazon) which links to a product sold on amazon. I would like to add the following code (required to implement google conversion tracking):
onclick="return gtag_report_conversion('http://example.com/your-link')"
Surprisingly, as far as I can see I can only add this code by directly editing the page HTML- which works but is not ideal. As I imagine this is a reasonably common requirement is there some GP feature that will allow me to add this code this without having to edit HTML?
I would much appreciate any advice!
Hi there,
I'm not sure if I fully understand.
Perhaps a hook would be what you are looking for?
https://docs.generatepress.com/article/hooks-element-overview/
Hi Leo, thanks for your response. It is not obvious to me how I would use a hook to implement this. Let me explain what I am trying to do. GeneratePress creates the following code (I have replaced the URLs) for the GIF:
<td><a href="[AMAZON URL]/dp/xxxxxxxxx"><img class=" wp-image-298 alignright" src="[WEBSITE URL]/wp-content/uploads/2018/05/buy2.gif" alt="" width="225" height="37" /></a></td>
I would this:
<td><a href=[AMAZON URL]//dp/xxxxxxxxxx"><img class=" wp-image-298 alignright" src="="[WEBSITE URL]/wp-content/uploads/2018/05/buy2.gif" alt="" width="225" height="37" onclick="return gtag_report_conversion('[AMAZON URL]//dp/xxxxxxxx')" /></a></td>
Is there some way to configure a hook that will inset this code (beginning onclick...)?
Hi there,
The suggestion from Leo for using an Element doesn't apply here - i believe he thought you were trying to add a Javascript eventListener - as opposed to an inline onClick event.
GP has no responsibility over that code you're generating - its a core WP editor function that manages that. The method you're using by editing HTML is the simplest method today.