Skip to content

Instantly share code, notes, and snippets.

@pixelstorm
Created October 12, 2024 18:47
Show Gist options
  • Save pixelstorm/19600c84d6365c2ef0d187da4636832e to your computer and use it in GitHub Desktop.
Save pixelstorm/19600c84d6365c2ef0d187da4636832e to your computer and use it in GitHub Desktop.
Track button clicks with a specific classname. The tracking script we are using is for LinkedIn.
// Get all elements with the class "pop-action"
const buttons = document.querySelectorAll('.pop-action');
// Iterate through the NodeList of buttons and attach click event listeners
buttons.forEach(function(button) {
button.addEventListener('click', function() {
// Code to run when a button is clicked
console.log(`Button "${button.textContent}" clicked.`);
window.lintrk('track',{ conversion_id: xxxxxxxx });
// You can perform additional actions here if needed
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment