Created
August 16, 2021 12:04
-
-
Save fredriccliver/d6dd3e8d93e625c89dc77769d81b6483 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function () { | |
document.querySelectorAll('a[href^="#"]').forEach((anchor) => { | |
anchor.addEventListener("click", function (e) { | |
// Get href link value | |
const targetUrl = this.getAttribute("href"); | |
// Track the event name as "anchor_click" and custom field name is "target", value is the href value. | |
firebase.analytics().logEvent('anchor_click', { target: targetUrl}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment