Hello,
We would like to track Load More button clicks and sent an event to google analytics. We have set up a WordPress Archive with the load more button
[wpv-pager-next-page][wpml-string context="wpv-views"]Load More[/wpml-string][/wpv-pager-next-page]
How is this possible?
Thank you
Hi, I'm not a Google Analytics expert so I'm not exactly sure. How would you set this up without Toolset? For example, if you had a basic text link and you wanted to track clicks on that link, how would you set that up in HTML / JavaScript?
Hello Christian,
For example, when we track Tabs click we have added the following code in our child theme javascript.js
jQuery(document).ready(function(jQuery){
jQuery("#fusion-tab_One").on("click", function(e){
gtag('event', 'Our_event ',{'event_category': ' Our_category ','event_label': 'Our_Label',});
return true;
});
We need the id of the Tab to track. So, in our case, we need id of Load More button but i can see any
<a class="wpv-filter-next-link js-wpv-pagination-next-link page-link " href="/?wpv_view_count=62151&wpv_paged=2" data-viewnumber="62151" data-page="2">Load More</a>
Thank you
You should be able to use the CSS classname instead:
jQuery(document).ready(function(jQuery){
jQuery(".js-wpv-pagination-next-link").on("click", function(e){
gtag('event', 'Our_event ',{'event_category': ' Our_category ','event_label': 'Our_Label',});
return true;
});
Hello,
I have added the code and its working but only the first time where the load more button is triggered
jQuery(document).ready(function(jQuery){
jQuery(".js-wpv-pagination-next-link").on("click", function(e){
alert("I am an alert box!");
return true;
});
});
Ah okay. Let's try this alternative:
jQuery(document).ready(function(jQuery){
jQuery(document).on("click", ".js-wpv-pagination-next-link", function(e){
alert("I am an alert box!");
return true;
});
});
That should keep the event listener working even after updates.
Hello Christian,
It works. You may close the ticket.
Thank you!