diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d4438b56..da7242d8e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Resolve problem with getting CMS block from cache - @qiqqq (#2499) - Make image proxy url work with relative base url - @cewald (#3158) - Fixed memory leak with enabled dynamicConfigReload - @dimasch (#3075) +- Fixed error for the orderhistory null for google-tag-manager extension - @cnviradiya (#3195) ### Changed / Improved - Shipping address is saved as default when not logged in user chooses to create account during checkout - @iwonapiotrowska (#2636) diff --git a/src/modules/google-tag-manager/hooks/afterRegistration.ts b/src/modules/google-tag-manager/hooks/afterRegistration.ts index b1c9eda6f4..a95dfb667f 100644 --- a/src/modules/google-tag-manager/hooks/afterRegistration.ts +++ b/src/modules/google-tag-manager/hooks/afterRegistration.ts @@ -70,23 +70,25 @@ export function afterRegistration (Vue, config, store, isServer) { { refresh: true, useCache: false } ).then(() => { const orderHistory = state.user.orders_history - const order = orderHistory.items.find((order) => order['entity_id'].toString() === orderId) - if (order) { - Vue.gtm.trackEvent({ - 'ecommerce': { - 'purchase': { - 'actionField': { - 'id': orderId, - 'affiliation': order.store_name, - 'revenue': order.total_due, - 'tax': order.tax_amount, - 'shipping': order.shipping_amount, - 'coupon': '' - }, - 'products': products + if (orderHistory) { + const order = orderHistory.items.find((order) => order['entity_id'].toString() === orderId) + if (order) { + Vue.gtm.trackEvent({ + 'ecommerce': { + 'purchase': { + 'actionField': { + 'id': orderId, + 'affiliation': order.store_name, + 'revenue': order.total_due, + 'tax': order.tax_amount, + 'shipping': order.shipping_amount, + 'coupon': '' + }, + 'products': products + } } - } - }) + }) + } } }) }