The WSL version we are currently using is 2.3.0.
I want to add a google analytics onclick event tracker to the my social widget elements so that we can analyze the number of people are clicking these sign up methods. Currently, the modal that pops up renders on page load in footer.php. In a separate JS file,I tried to target the Facebook widget, for example, by doing:
$(document).ready(function() {
$(".tbf-modal-join a.wp-social-login-provider.wp-social-login-provider-facebook").attr('onlick', 'ga('send', 'event', 'Navigation', 'WSL-Facebook');
})
})
This however, didn't work for me (as well as numerous other variations of classes, attributes, eg 'setAttribute' instead of attr).
Could anyone please suggest how this could be done?
Thanks!
Try this:
$(document).ready(function() {
$('.wp-social-login-provider-facebook').on('click', function() {
ga('send', 'event', 'Navigation', 'WSL-Facebook');
});
});
Basically, instead of trying to add the event via an attribute value to the onclick
attribute, just add the click handler directly via jQuery.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.