Tagged: code, enfold, event tracking, google analytics, Tracking
-
AuthorPosts
-
February 16, 2017 at 11:49 am #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!
/RasmusFebruary 21, 2017 at 7:10 am #749751Hi 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#snippetRegards,
IsmaelFebruary 24, 2017 at 11:41 am #751342Hi,
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 & FormFebruary 27, 2017 at 5:08 am #752125Hey!
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,
IsmaelApril 22, 2017 at 10:22 am #781637Hi, 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’)”);April 22, 2017 at 6:43 pm #781741Hi,
Try this:$('.button-contact a').attr('onclick', 'ga('send', 'event', 'button', 'click', 'Send Request')');
Best regards,
MikeApril 22, 2017 at 7:31 pm #781752Hi 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’)’);April 23, 2017 at 9:32 am #781912Hi,
Try this code:
$('.button-contact a').on('click', function(e){ ga(‘send’, ‘event’, ‘button’, ‘click’, ‘Send Request’); });
Best regards,
John TorvikApril 24, 2017 at 3:24 am #782110Hi 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 tokenApril 24, 2017 at 5:12 am #782132Hi,
Try to replace the single quotes from:
’
to
'
I would suggest replacing them manually by typing the single quotes. Hope this helps.
Best regards,
NikkoApril 24, 2017 at 6:04 am #782154Hi Nikko, thank you, it works, but works only with standart buttons, not with the buton in the Contact forms?
April 25, 2017 at 7:39 pm #783050Hi 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 -
AuthorPosts
- You must be logged in to reply to this topic.