-
AuthorPosts
-
November 2, 2016 at 3:49 pm #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. thomasNovember 2, 2016 at 8:48 pm #707339Hey 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 ago by Vinay.
November 3, 2016 at 6:19 pm #707892i have tried the script but it doesnt work. Do you have any other Idea to bring google tracking to live?
Best regards
ThomasNovember 3, 2016 at 6:51 pm #707907Hi!
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,
BasilisNovember 7, 2016 at 5:13 pm #709367I’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’);November 10, 2016 at 5:04 am #710527Hi,
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,
NikkoNovember 10, 2016 at 12:24 pm #710669It 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
}November 10, 2016 at 3:17 pm #710739Hi,
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 -
AuthorPosts
- The topic ‘Google conversion Pixel on click button doesnt count’ is closed to new replies.