Analytics instrumentation
Overview
Instrumentation is the process of adding code to your storefront to collect data about user interactions and behaviors. This data powers critical Adobe Commerce features and provides valuable insights into your customers’ shopping journey.
Why Instrumentation Matters
User interaction events collected through instrumentation enable:
- Adobe Sensei features: Intelligent merchandising and search result optimization in Live Search
- Product recommendations: Personalized product suggestions based on user behavior
- Performance analytics: Detailed dashboards showing search performance, conversion rates, and user engagement
- Business intelligence: Data-driven insights for inventory management and marketing strategies
Adobe Client Data Layer (ACDL)
The Adobe Client Data Layer (ACDL) is a standardized JavaScript framework that simplifies data collection on your storefront. It provides a unified approach to capturing, storing, and transmitting user interaction data.
Key Capabilities
The ACDL enables your storefront to:
- Collect interaction data: Track user behaviors like product views, searches, cart actions, and purchases
- Standardize data format: Ensure consistent data structure across all events
- Manage event timing: Control when and how data is sent to analytics services
- Support multiple integrations: Work seamlessly with Adobe Experience Platform, Analytics, and other tools
Core API Functions
Function | Description | Use Case |
---|---|---|
push() | Add data or trigger events | Send product view, cart addition events |
getState() | Retrieve current data layer state | Access user session or cart information |
addEventListener() | Register event listeners | React to specific user actions |
getHistory() | View event history | Debug or audit data collection |
Configuration
Store Configuration
To enable proper event collection, you need to configure your store’s analytics settings. This configuration tells the instrumentation system about your store’s identity and structure. Refer to the Commerce Configuration documentation for more information.
Required Configuration Parameters
"analytics": { "base-currency-code": "USD", "environment": "Testing", "store-id": 1, "store-name": "Main Website Store", "store-url": "https://adobe-commerce.example.com", "store-view-id": 1, "store-view-name": "Default Store View", "website-id": 1, "website-name": "Main Website"}
Configuration Parameters Explained
Parameter | Description | Example | Required |
---|---|---|---|
base-currency-code | Default currency for your store | "USD" , "EUR" | Yes |
environment | Current environment type | "Testing" , "Production" | Yes |
store-id | Unique identifier for your store | 1 , 2 | Yes |
store-name | Human-readable store name | "Main Website Store" | Yes |
store-url | Your store’s primary URL | "https://example.com" | Yes |
store-view-id | Unique identifier for store view | 1 , 2 | Yes |
store-view-name | Human-readable store view name | "Default Store View" | Yes |
website-id | Unique identifier for website | 1 , 2 | Yes |
website-name | Human-readable website name | "Main Website" | Yes |
Data Services Configuration
For the instrumentation to work with Adobe Commerce’s data services, you’ll need additional configuration parameters. The easiest way to obtain these is through the magento/module-data-services-graphql
module, which exposes the necessary GraphQL endpoints.
Required for Data Services
- Catalog Service credentials: For product data synchronization
- SaaS environment ID: Links your storefront to Adobe Commerce SaaS services
- API keys: Authenticate with Adobe Commerce backend services
Event Collection and Validation
Automatic Event Collection
The Commerce boilerplate includes the Storefront Events Collector, which automatically:
- Listens for ACDL events: Monitors the data layer for new events
- Validates event structure: Ensures events conform to required schemas
- Batches and sends data: Efficiently transmits events to Adobe Commerce
- Handles errors: Manages network issues and retry logic
Event Types Collected
Your instrumentation will automatically track:
- Shopping events: Cart updates and views (
addToCart
,removeFromCart
,shoppingCartView
), page views (pageView
,productPageView
), checkout (startCheckout
,completeCheckout
) and more. - Customer profile events: Customer login (
signIn
), customer logout (signOut
), create account (createAccount
), edit account (editAccount
). - Search events: Search query (
searchRequestSent
) and search results (searchResponseReceived
).
Event Schema Compliance
All events must comply with the schema defined by the Storefront Event SDK. This ensures compatibility with Adobe Commerce services and analytics tools.
Validation and Testing
The following sections describe how to validate and test your event implementation.
Automated Validation
You can validate your event implementation using the ACDL Event Validator. This tool checks:
- Event structure: Verifies required fields are present
- Data types: Ensures values match expected formats
- Schema compliance: Confirms events follow Storefront Event SDK specifications
Manual Testing Steps
- Open browser developer tools and navigate to the Console tab
- Check for ACDL: Verify
window.adobeDataLayer
exists and contains events - Monitor network requests: Look for successful data transmission to Adobe services
- Validate event data: Inspect event payloads for completeness and accuracy
- Confirm that event data is collected: To confirm that data is being collected from your Commerce store, use the Adobe Experience Platform debugger to examine your Commerce site.
Common Validation Issues
- Missing configuration: Ensure all required analytics parameters are set
- Incorrect store IDs: Verify store and website IDs match your Adobe Commerce setup
- Network connectivity: Check that your storefront can reach Adobe Commerce endpoints
- Event timing: Confirm events fire at the correct moments in the user journey
Troubleshooting Configuration Issues
Problem: Events not being sent
Solution:
- Verify your
config.json
contains all required analytics parameters - Check that store IDs match your Adobe Commerce backend configuration
- Ensure the Storefront Events Collector is loading properly
Problem: Invalid event data
Solution:
- Use the ACDL validator to check event structure
- Verify custom events follow the Storefront Event SDK schema
- Check for JavaScript errors that might corrupt event data
Troubleshooting Integration Issues
Problem: Live Search not receiving data
Solution:
- Confirm your SaaS environment ID is correctly configured
- Verify API credentials are valid and have necessary permissions
- Check that product catalog is properly synchronized
For additional troubleshooting, refer to the Live Search Data Collection documentation.
Best Practices
Implementation Guidelines
- Test thoroughly: Validate events in development before deploying to production
- Monitor regularly: Set up alerts for data collection failures
- Follow schemas: Always comply with Storefront Event SDK specifications
- Optimize performance: Batch events when possible to reduce network overhead
Data Quality
- Validate user inputs: Sanitize data before adding to events
- Handle edge cases: Account for scenarios like network failures or missing data
- Maintain consistency: Use standardized naming and formatting across all events
- Respect privacy: Ensure compliance with data protection regulations