diff --git a/CHANGELOG.md b/CHANGELOG.md index 042ea0d..d84b1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### [Unreleased] +#### Fixed +- Updated customer.js to correctly handle promise returned from isIdentified + ### [4.1.1] - 2023-12-12 #### Added diff --git a/view/frontend/web/js/customer.js b/view/frontend/web/js/customer.js index e9bac64..231ab19 100644 --- a/view/frontend/web/js/customer.js +++ b/view/frontend/web/js/customer.js @@ -12,13 +12,16 @@ define([ customerData.getInitCustomerData().done(function () { var customer = customerData.get('customer')(); - if(_.has(customer, 'email') && customer.email && !klaviyo.isIdentified()) { - klaviyo.identify({ - '$email': customer.email, - '$first_name': _.has(customer, 'firstname') ? customer.firstname : '', - '$last_name': _.has(customer, 'lastname') ? customer.lastname : '' - }); - } + klaviyo.isIdentified().then((identified)=> { + if(_.has(customer, 'email') && customer.email && !identified) { + klaviyo.identify({ + '$email': customer.email, + '$first_name': _.has(customer, 'firstname') ? customer.firstname : '', + '$last_name': _.has(customer, 'lastname') ? customer.lastname : '' + }); + } + }); + }); });