Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #707176

    Hi, I need to add an »onclick event« to tracking with google analytics. I added the analytics Skript and changed the code from the SEO-Agnecy as it was descriped in another thread and at the google support pages.

    —–Code from the SEO Agency—-
    »Diese Pixel muss in jeden klickbaren Button für Terminvereinbarung eingebaut werden«
    onClick=”ga(‘send’, {
    hitType: ‘event’,
    eventCategory: ‘Button’,
    eventAction: ‘click’,
    eventLabel: ‘Termin vereinbaren’
    });”

    ———- I added this to the Child-Theme funktion.php —-

    function add_custom_script(){
    ?>
    <script>
    (function($){
    $(window).load(function() {
    $(‘.terminus a’).on(‘click’, function() {
    ga(‘send’, ‘event’, ‘Button’, ‘click’, ‘Termin vereinbaren’);
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_script’);

    ——-
    I also added a custon Css Class to the Button called (»terminus«)

    I can’t find the bug, but it doesnt work. Any ideas why.
    Thanks in advance. thomas

    #707339

    Hey ThoNeumann,

    Thank you for contacting us.

    While adding custom jQuery code to wordpress functions.php the “$” sign should be replaced with word “jQuery”.

    Your code should look like:

    function add_custom_script1(){
    ?>
    <script>
    (function($){
    jQuery(window).load(function() {
    jQuery(‘.terminus a’).on(‘click’, function() {
    ga(‘send’, ‘event’, ‘Button’, ‘click’, ‘Termin vereinbaren’);
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_script1’);

    Try the above code and let us know if you have any issues.

    Best regards,
    Vinay

    • This reply was modified 8 years, 1 month ago by Vinay.
    #707892

    i have tried the script but it doesnt work. Do you have any other Idea to bring google tracking to live?
    Best regards
    Thomas

    #707907

    Hi!

    Please add the code as following

    function add_custom_script1(){
    ?>
    <script>
    (function($){
    jQuery(window).load(function() {
    jQuery('.terminus a’).on('click’, function() {
    ga('send’, 'event’, 'Button’, 'click’, 'Termin vereinbaren’);
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer’, 'add_custom_script1’);

    let us know if it works, please copy from forums not email

    Regards,
    Basilis

    #709367

    I’ve tried several code modifications with: “, ‘ , and tried to copy the script to the Analytics Code Field and at Footer insertion. Without any sucees. Any Ideas? To make it work.

    function add_custom_script1(){
    ?>
    <script>
    (function($){
    jQuery(window).load(function() {
    jQuery(‘.terminus a’).on(‘click’, function() {
    ga(‘send’, ‘event’, ‘Button’, ‘click’, ‘Termin vereinbaren’);
    });
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘add_custom_script1’);

    #710527

    Hi,

    I checked it and it doesn’t seem to run the click event, I modified functions.php and inserted the click event in this script:

    add_action('wp_footer', 'ava_custom_script');
    function ava_custom_script(){
    ?>
    <script type="text/javascript">
    (function($) {
    	function a() {
    		$('.av-masonry-image-container img').each(function() {
    			$(this).removeAttr('title');
    		});
    	}
    
    	a();
    })(jQuery);
    </script>
    <?php
    }

    And it should look like this now:

    add_action('wp_footer', 'ava_custom_script');
    function ava_custom_script(){
    ?>
    <script type="text/javascript">
    (function($) {
    	function a() {
    		$('.av-masonry-image-container img').each(function() {
    			$(this).removeAttr('title');
    		});
    
    		$('.terminus a').click( function() {
    			ga('send', 'event', 'Button', 'click', 'Termin vereinbaren');
    		});
    	}
    
    	a();
    })(jQuery);
    </script>
    <?php
    }

    I tested it out and it runs the click event. Let us know if it works on your end too. :)

    Best regards,
    Nikko

    #710669

    It works now. With a little modification. I put the number »,1« at the end of the ga-code-line. Thanx for your support.

    add_action(‘wp_footer’, ‘ava_custom_script’);
    function ava_custom_script(){
    ?>
    <script type=”text/javascript”>
    (function($) {
    function a() {
    $(‘.av-masonry-image-container img’).each(function() {
    $(this).removeAttr(‘title’);
    });

    $(‘.terminus a’).click( function() {
    ga(‘send’, ‘event’, ‘Button’, ‘click’, ‘Termin vereinbaren’ ,1);
    });
    }

    a();
    })(jQuery);
    </script>
    <?php
    }

    #710739

    Hi,

    Glad it works! We really appreciate it if you rate our theme on themeforest https://themeforest.net/downloads :)
    To know more about enfold features please check – http://kriesi.at/documentation/enfold/
    Thank you for using Enfold :)

    Best regards,
    Vinay

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Google conversion Pixel on click button doesnt count’ is closed to new replies.