On click tag

hi guys
i want to add google tags to my buttons so i can track conversions
so i added some code in the head but i dont know how to add the on click tag to my buttons.
would love your help to show me how.

Amir

Hey Amir,

You can follow a similar method like suggested in this thread: https://theme.co/apex/forum/t/add-onclick-to-header-and-v2-element-button/40284/4?u=christian_y

Thanks.

hi i am sorry but my knowledge of javascript is very limited
i am trying to add the following code to a button which has a phone link or a mailto function

call now

can you please show me some screen shots on how to do so.
i would appreciate it very much

Hi,

You can add a unique class to your button element. Then use that class to trigger on click.

Add this in Theme Options > JS

jQuery(".call-button").on("click", function() {
     return  gtag_report_conversion('tel:0507264874');
});

Hope that helps

hi thanks for your help i appreciate it very much.
the code i actually need to implement in the button is this:

<script> function gtag_report_conversion(url) { var callback = function () { if (typeof(url) != 'undefined') { window.location = url; } }; gtag('event', 'conversion', { 'send_to': 'AW-774559316/P3-ECLqjxZIBENSsq_EC', 'event_callback': callback }); return false; } </script>

can you please show me how to do so

Hi There,

Please change the previous code of Paul to this:

jQuery(".call-button").on("touchend click", "gtag_report_conversion");

Then update your code to this:

<script>
	function gtag_report_conversion() {
	
		var url = jQuery(this).attr('href');
		var callback = function () {
			if (typeof(url) != 'undefined') {
				window.location = url;
			}
		};
		gtag('event', 'conversion', {
			'send_to': 'AW-774559316/P3-ECLqjxZIBENSsq_EC',
			'event_callback': callback
		});
		return false;

	}
</script>

Hope it helps :slight_smile:

but how do i associate it with a certain button or button class?
like the .call-button class above

Hi again,

If you’ve already assigned a class call-button to your button then just add the following code to the page JS section where you’ve the button:

jQuery(".call-button").on("touchend click", "gtag_report_conversion");

This will bind the click event to the button that has a class call-button.

Hope this helps!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.