Site logo

Archived topic

Can not add click tracking code to Generateblock button

5 replies · Started by Paul on April 7, 2022

Viewing posts 1–6 of 6

hi, how are you

im adding clicking tracking code to footer generateblck button

the orignal button html code is

Contact Us

google clicking tracking code to the button

<button onclick="return gtag_report_conversion('https://www.romlicenwatch.com/contact-us/')">contact us</button>

when i add it to previous code, the button will not work, so pls guide it, thanks

Hi there,

you can't add that to a GB Button ( or any Block Button ).

You would need to add the <button> code to a HTML block to use that method.

Hi david

yes, you are right, need to add it to the html block, but still not useful

below is html code of the contact us button

https://prnt.sc/wb-Wm6fpb6jq

also this one screenshot https://prnt.sc/P3nEXgq66KPr

How do I put tracking html code into the original button code? pls guide, thanks

Hi Paul,

As mentioned by David, you may use the HTML Block as such: https://share.getcloudapp.com/jkuvvOXZ

If you wish to add it to the GB Button Block, one approach to do this is through JS. For instance: https://share.getcloudapp.com/xQuqqOEE

Also see: https://share.getcloudapp.com/X6uEE5nO

As shown I added this code through a Hook Element hooked to wp_footer display on the specific page:

<script>
var elgtag = document.querySelector(".my-gtag-button");
	elgtag.setAttribute("onclick", "return gtag_report_conversion('http://example.com/your-link')");
</script>

Kindly replace the example link or the entire return statement with the appropriate one.

I also added custom class my-gtag-button to the Button as such: https://share.getcloudapp.com/BluooRR7

Hope this helps. :)

hi Fernando,

thanks for ur response.

method 1, using HTML Block and edit them directly.
method 2, adding conversion code to GB button block,
step 1, added Corresponding event tracking code on the specific page, for example: https://prnt.sc/IWLUtIM-zbNz
step 2, add custom class to the corresponding code or text link

i think the above is all you mentioned
thanks

The HTML method you replace the <button> with a link <a> eg.

<a class="button" onclick="return gtag_report_conversion('http://example.com/your-link');" href="http://example.com/your-link">Contact Us</a>

this has the href for the button to link to the page.
the class="button" will apply the GP button styles to it.

This archived topic is closed to new replies.