adobe / adobe/aem-core-cif-components

EventCollectorContextProvider missing context values when setting storefront instance

Open
#1,003 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
109
Forks
78
Avg merge
4d 18h
Merged PRs (30d)
4

Description

### Expected Behaviour

1. StorefrontInstanceContext requires the following fields in the snowplow schema for
iglu:com.adobe.magento.entity/storefront-instance/jsonschema/3-0-1

"environmentId",
"environment",
"storeUrl",
"websiteId",
"storeId",
"storeViewId",
"websiteName",
"storeName",
"storeViewName",
"baseCurrencyCode",
"storeViewCurrencyCode"

2. Expected behavior is the EventCollectorContextProvider has these fields in the context when applying mse.context.setStorefrontInstance(context).

3. Expected add-to-cart event storefront instance to include these fields but only saw baseCurrencyCode and storeViewCurrencyCode.

There's also another issue where the cart context in mse will not be set before this runs. Causing the product page view event to fail since it requires the shopping cart context to be set before it publishes. I had to change the file to grab the cart and update shopping cart context.

### Actual Behaviour
1. It only has baseCurrencyCode and storeViewCurrencyCode in the context.

### Reproduce Scenario (including but not limited to)
1. Implement EventCollectorContextProvider and try to send an add-to-cart event.
2. Check the snowplow schema and storefront instance will only have two fields in data when schema expects more listed above.

## Fix for the issue

1. Created custom ExperiencePlatformConnector from the source code and added fields to the graphql query and when setting the storefront instance context.

### Changes made to graphql query

import { gql } from '@apollo/client';
export default gql`
query DataServicesStorefrontInstanceContext {
dataServicesStorefrontInstanceContext {
catalog_extension_version
environment
environment_id
store_code
store_id
store_name
store_url
store_view_code
store_view_id
store_view_name
website_code
website_id
website_name
}
storeConfig {
base_currency_code
store_code
}
}

### Changes made to Storefront Instance context
storeConfigQuery().then(({ data }) => {
const {
environment,
environment_id,
website_id,
website_code,
website_name,
store_url,
store_id,
store_code,
store_name,
store_view_id,
store_view_code,
store_view_name,
catalog_extension_version
} = data.dataServicesStorefrontInstanceContext;
const { base_currency_code } = data.storeConfig;
const context = {
environmentId: environment_id,
environment,
storeUrl: store_url,
websiteId: website_id,
websiteCode: website_code,
storeId: store_id,
storeCode: store_code,
storeViewId: store_view_id,
storeViewCode: store_view_code,
websiteName: website_name,
storeName: store_name,
storeViewName: store_view_name,
baseCurrencyCode: base_currency_code,
storeViewCurrencyCode: base_currency_code,
catalogExtensionVersion: catalog_extension_version
};

mse.context.setStorefrontInstance(context);
});
`;

Contributor guide

Open the contributing guide

Research direction

Start with EventCollectorContextProvider and the ExperiencePlatformConnector entry point, then inspect the GraphQL query and the code that calls mse.context.setStorefrontInstance(context). Verify that the storefront fields are populated and that shopping cart context is available before the product page view and add-to-cart events are published.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.