I want to add Pixel Event JavaScript Code to my WordPress site. I have added Code to the particular Page but now I want to Add JavaScript code to Button so that I can Track the Clicks.
I have added the JS Code for Pages in Header.php File in Wordpress as given Below:
<?PHP if(is_page('Page-name') : ?>
<script>
My Script
</script>
<?PHP endif ?>
Similarly, Can I Add JS code to Button to track the button Clicks?
Code to track which element was clicked
var arrayWithElements = new Array();
document.onclick = clickListener;
function clickListener(e) {
var clickedElement;
if(e == null) {
clickedElement = event.srcElement;
} else {
clickedElement = e.target;
}
arrayWithElements.push(clickedElement)
alert(arrayWithElements);}
Code that will be used on a identical HTML-page
document.someHowGetTheElement().onclick();
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.