klaviyo / magento2-klaviyo

38 stars 51 forks source link

Customer not identified after entering email address on shipping step #306

Open milosreccode opened 3 months ago

milosreccode commented 3 months ago

Environment details

PHP version: 8.1.13 Magento version: 2.4.6 Klaviyo extension version: 4.1.4

Steps to reproduce

  1. Add any product to cart
  2. Navigate to checkout
  3. Enter email address
  4. Unfocus email field by clicking outside it, this will trigger customer identification and quote update

Expected result

If customer is not already identified, it will be identified now by using email that customer entered in the email field.

Actual result

Custoomer is not identified because window.klaviyo.isIdentified() returns promise, but it is used as boolean in if statement.

Additional information

It seems that changing

if (!window.klaviyo.isIdentified()) {
  window.klaviyo.push(['identify', {
    '$email': self._email
  }]);
}

to

window.klaviyo.isIdentified().then((isIdentified) => {
  if (!isIdentified) {
    window.klaviyo.push(['identify', {
      '$email': self._email
    }]);
  }
});

is solution for this problem.