From 59e39ad6c314132e1772cd12212c788d716bbb3f Mon Sep 17 00:00:00 2001 From: Helen Lin Date: Mon, 17 Jun 2024 16:58:17 -0700 Subject: [PATCH] clean up --- .../src/analytics-manager/ShopifyAnalytics.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/hydrogen/src/analytics-manager/ShopifyAnalytics.tsx b/packages/hydrogen/src/analytics-manager/ShopifyAnalytics.tsx index f67572a20..62cf59e1e 100644 --- a/packages/hydrogen/src/analytics-manager/ShopifyAnalytics.tsx +++ b/packages/hydrogen/src/analytics-manager/ShopifyAnalytics.tsx @@ -336,22 +336,18 @@ function missingErrorMessage( viewKeyName?: string, ) { if (type === 'cart') { + const name = `${ + isVariantField ? 'merchandise' : 'merchandise.product' + }.${fieldName}`; // eslint-disable-next-line no-console console.error( - `[h2:error:ShopifyAnalytics] Can't set up cart analytics events because the \`cart.lines[].${ - isVariantField ? 'merchandise' : 'merchandise.product' - }.${fieldName}\` value is missing from your GraphQL cart query. In your project, search for where \`fragment CartLine on CartLine\` is defined and make sure \`${ - isVariantField ? 'merchandise' : 'merchandise.product' - }.${fieldName}\` is part of your cart query. Check the Hydrogen Skeleton template for reference: https://github.com/Shopify/hydrogen/blob/main/templates/skeleton/app/lib/fragments.ts#L25-L56.`, + `[h2:error:ShopifyAnalytics] Can't set up cart analytics events because the \`cart.lines[].${name}\` value is missing from your GraphQL cart query. In your project, search for where \`fragment CartLine on CartLine\` is defined and make sure \`${name}\` is part of your cart query. Check the Hydrogen Skeleton template for reference: https://github.com/Shopify/hydrogen/blob/main/templates/skeleton/app/lib/fragments.ts#L25-L56.`, ); } else { + const name = `${viewKeyName || fieldName}`; // eslint-disable-next-line no-console console.error( - `[h2:error:ShopifyAnalytics] Can't set up product view analytics events because the \`${ - viewKeyName || fieldName - }\` is missing from your \`\`. Make sure \`${ - viewKeyName || fieldName - }\` is part of your products data prop. Check the Hydrogen Skeleton template for reference: https://github.com/Shopify/hydrogen/blob/main/templates/skeleton/app/routes/products.%24handle.tsx#L159-L165.`, + `[h2:error:ShopifyAnalytics] Can't set up product view analytics events because the \`${name}\` is missing from your \`\`. Make sure \`${name}\` is part of your products data prop. Check the Hydrogen Skeleton template for reference: https://github.com/Shopify/hydrogen/blob/main/templates/skeleton/app/routes/products.%24handle.tsx#L159-L165.`, ); } }