Hi guys,
I was looking at an old post on Google Analytics event tracking (https://kriesi.at/support/topic/please-clear-this-up-for-em-ga-tracking-2/), and tried to replicate it on my website.
Here is the code :
function add_custom_script(){
if(is_page(array(23)){
?>
<script>
(function($){
$(window).load(function() {
$('.button-1 a').on('click', function() {
ga('send', 'event', 'button', 'click', 'button-1');
});
});
})(jQuery);
</script>
<?php
}
}
add_action('wp_footer', 'add_custom_script');
The enfold editor tells me that ther is a syntax error with the “if” conditionnal.
When I delete the “If” conditional the whole thing works, but I need the “if” conditional to use this script only on one page…
Could you guys help me please ?
well if you only have one page get rid of array. – and btw. i think there is one round bracket missing
if(is_page(array(23))){
but try
if(is_page(23)){
Hi,
Are you adding that in a Code Block or something similar? If so then it likely won’t work, please try it in functions.php in your child theme instead.
Best regards,
Rikard
Hi Guenni007,
Thanks for the help !!!
Hey pberquet,
Did you need further help with this topic or shall we close?
Best regards,
Jordan Shannon