Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #747910

    Hi!

    I’ve added a couple (4) buy-buttons on my web site, which directs the visitor to a new page.

    Now I want to track the amount of clicks on these specific buttons using Google Analytics. I have read back and forth across many threads on here, but I think that my understanding of coding in its general form is on a more basic level than most people here.

    The “progress” I’ve made so far has been the following:

    – added “add_theme_support(‘avia_template_builder_custom_css’);” in the editor, activating the Custom CSS class-field on my buttons.
    – Put “_trackEvent(‘Button’,‘onClick’,‘Steam_button_clicks’,‘opt_value’,‘opt_noninteraction’)” in one of those buttons (this is where i start to get uncertain about what I’m actually doing)
    – added new “goals” in Google Analytics for each button, which I thought I successfully linked with the piece of code above.

    To sum it up – I need an explanation on how this process should be carried out (preferrably quite simplified). That would help a great deal.

    Thanks in advance!
    /Rasmus

    #749751

    Hi imageform!

    Thank you for using Enfold.

    Did you add the onclick attribute inside the custom css class field? Please remove that then replace it with a unique class attribute. For example, in the Steam button, use “steam-button”. The onclick attribute can be added via jquery. Add this in the functions.php file:

    function ava_custom_script() {
    ?>
    	<script type="text/javascript">
    	(function($) {
    		// steam button onclick attribute
    		$(".steam-button a").attr("onclick", "ga('send', 'event', 'category', 'action', 'opt_label', opt_value, {'nonInteraction': 1})");
    
    		// another button onclick attribute
    		$(".another-button a").attr("onclick", "ga('send', 'event', 'category', 'action', 'opt_label', opt_value, {'nonInteraction': 1})");
    	})(jQuery);
    	</script>
    <?php
    }
    add_action('wp_footer', 'ava_custom_script');

    Adjust the events parameters.

    // https://kriesi.at/support/topic/google-analytics-event-tracking-2/
    // https://support.google.com/analytics/answer/6164470?hl=en
    // https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs#snippet

    Regards,
    Ismael

    #751342

    Hi,

    Thank you for your help. Although, I still don’t seem to get it right.

    I pasted the code to functions.php as follows:

    function ava_custom_script() {
    ?>
    <script type=”text/javascript”>
    (function($) {
    // steam button onclick attribute
    $(“.heist-steam-button a”).attr(“onclick”, “ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Steam button click’, opt_value, {‘nonInteraction’: 1})”);
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘ava_custom_script’);

    Also, I changed the onclick attribute to now say “heist-steam-button”.

    As you can see, I matched the event parameters with those of the created goals in Google Analytics. Am I still missing something?

    Thanks in advance.

    Rasmus
    Image & Form

    #752125

    Hey!

    The onclick attribute is being applied correctly but I’m not sure if that’s the correct values. Please review their documentation regarding the tracking events, links above.

    <a href="http://store.steampowered.com/app/322190/" class="avia-button avia-button-fullwidth  avia-icon_select-no avia-color-custom " target="_blank" style="color:#ffffff; background-color:#171a21;  " onclick="ga('send', 'event', 'button', 'click', 'Steam button click', opt_value, {'nonInteraction': 1})"><span class="avia_iconbox_title">Steam</span><span class="avia_button_background avia-button avia-button-fullwidth avia-color-custom" style="background-color:#6d6869; "></span></a>
    

    Best regards,
    Ismael

    #781637

    Hi, Did you resolve that problem?

    1) I use this script in function php:
    function ava_custom_script() {
    ?>
    <script type=”text/javascript”>
    (function($) {
    $(“.button-contact a”).attr(“onclick”, “ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’)”);
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘ava_custom_script’);

    2) in button i puc custom CSS code button-contact

    3) Made a goal in Analytics with values from script.

    Not workig(((
    Also in debugger i have message
    Uncaught SyntaxError: missing ) after argument list
    in this line:
    $(“.button-contact a”).attr(“onclick”, “ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’)”);

    #781741

    Hi,
    Try this:

    $('.button-contact a').attr('onclick', 'ga('send', 'event', 'button', 'click', 'Send Request')');

    Best regards,
    Mike

    #781752

    Hi Mike! Just after page loading i have the same thing…
    Console:
    (index):671 Uncaught SyntaxError: missing ) after argument list
    Line:
    $(‘.button-contact a’).attr(‘onclick’, ‘ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’)’);

    #781912

    Hi,

    Try this code:

    $('.button-contact a').on('click', function(e){ ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’); });
    

    Best regards,
    John Torvik

    #782110

    Hi John,

    Here is my script code (like in Enfold Bible):

    function ava_custom_script() {
    ?>
    <script type=”text/javascript”>
    (function($) {
    // steam button onclick attribute
    $(‘.button-contact a’).on(‘click’, function(e){ ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’); });
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘ava_custom_script’);

    And other error:
    Uncaught SyntaxError: Invalid or unexpected token

    #782132

    Hi,

    Try to replace the single quotes from:

    to

    '

    I would suggest replacing them manually by typing the single quotes. Hope this helps.

    Best regards,
    Nikko

    #782154

    Hi Nikko, thank you, it works, but works only with standart buttons, not with the buton in the Contact forms?

    #783050

    Hi KidLoop,

    In contact forms you have to target input type=submit most of the time. Could you give us a link to a page with a form?

    Best regards,
    Victoria

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