Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #943119

    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 ?

    #943131

    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)){
    #943445

    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

    #943666

    Hi Guenni007,

    Thanks for the help !!!

    #943695

    Hey pberquet,

    Did you need further help with this topic or shall we close?

    Best regards,
    Jordan Shannon

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.