Last active
May 27, 2022 17:09
-
-
Save Aeickelman40/d0a28bf45bae2589e18242062b20561b to your computer and use it in GitHub Desktop.
Checkout page observer
This file contains 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
// 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