Hello,
I'm in the process of adding Amplitude tracking to our site and ran into a small problem. I would like to add the following behavior to the existing onclick handler of the submission button (in this example the newsletter submission button):
const newsletterSubmissionHandler = () => {
const eventProperties = {
page: window.location.href
};
amplitude.track('Form Submitted - Newsletter', eventProperties);
}
So far I've tried the following code injection without success:
const newsletterButton = document.getElementsByClassName("newsletter-form-button")[0];
const newsletterSubmissionHandler = () => {
const eventProperties = {
page: window.location.href
};
amplitude.track('Form Submitted - Newsletter', eventProperties);
}
addEvent(newsletterButton, "click", newsletterSubmissionHandler);
I'm wondering what's proper way to do this? I haven't had much success with searching online since adding onclick behaviors dynamically seems like a niche case.