Skip to content

Instantly share code, notes, and snippets.

@Aeickelman40
Last active May 27, 2022 17:09
Show Gist options
  • Save Aeickelman40/d0a28bf45bae2589e18242062b20561b to your computer and use it in GitHub Desktop.
Save Aeickelman40/d0a28bf45bae2589e18242062b20561b to your computer and use it in GitHub Desktop.
Checkout page observer
// Solution idea #1: Check to see if 'CONTINUE' button is clicked
initContinueButtonChecked() {
const continueBtn = document.querySelector('#checkout-customer-continue')
const emailField = document.querySelector('#email')
this.observeElement(continueBtn, (element) => {
if (!element) return
// set up event listener for if continue button was clicked
continueBtn.addEventListener('click', (event) => {
// once button is clicked, email input is no longer there
if (!emailField) {
// fire data layer call used by analytics (can we console.log this?)
window.cwDatalayer.getDatalayer().customer
}
}
})
}
// Solution idea #2: Check to see if email input does not exist by observing
initCheckEmailField() {
this.observeElement(`input[name*="${email}"]`, (element) => {
if (!element) return
// fire cwDatalayer method?
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment