Skip to content

Configuration & Modes

Configure the analytics system through window.nextConfig to control tracking behavior, enable providers, and set operational modes.

window.nextConfig = {
apiKey: 'your-api-key',
storeName: 'my-store', // Important for Facebook deduplication
analytics: {
enabled: true,
debug: false,
mode: 'auto',
providers: {
gtm: { enabled: true },
facebook: {
enabled: true,
settings: { pixelId: 'YOUR_PIXEL_ID' }
},
rudderstack: { enabled: true },
custom: {
enabled: true,
settings: { endpoint: 'https://api.yourapp.com/analytics' }
}
}
}
};
OptionTypeDefaultDescription
enabledbooleanfalseMaster switch for all analytics tracking
debugbooleanfalseEnable detailed console logging for troubleshooting
modestring'auto'Tracking mode: 'auto' or 'manual'
providersobject{}Provider configurations (GTM, Facebook, RudderStack, custom)
OptionTypeDescription
storeNamestringRequired for Facebook Pixel - Used for purchase deduplication

Auto mode automatically tracks common e-commerce events without manual intervention.

analytics: {
mode: 'auto'
}

Automatically tracked events:

EventTriggerDescription
dl_user_dataPage load, route changesBase user event with cart contents
dl_view_item_listCollection/category pagesProduct list views (when URL matches patterns)
dl_view_itemSingle product pagesProduct detail view (1 product with data-next-package-id)
dl_add_to_cartCart additionsWhen using data attributes or cart methods
dl_remove_from_cartCart removalsWhen using cart methods
dl_begin_checkoutCheckout page loadCheckout process initiation
dl_add_shipping_infoShipping form submissionShipping information entered
dl_add_payment_infoPayment form submissionPayment method selected
dl_purchaseOrder completionQueued and fired on confirmation page

Events requiring manual tracking:

  • dl_sign_up - User registration
  • dl_login - User login
  • Custom business events

Event Queue:

Events with redirects (like dl_purchase) are queued to sessionStorage and automatically fired after navigation completes.

When to use auto mode:

  • Standard e-commerce implementations
  • Minimal custom tracking requirements
  • Want to minimize code complexity
  • Need consistent tracking across pages

Full control over when and how events are tracked.

analytics: {
mode: 'manual'
}

All events must be manually tracked using the tracking API.

When to use manual mode:

  • Need complete control over event timing
  • Custom e-commerce flows that don’t match standard patterns
  • Want to track only specific events
  • Implementing custom event logic

Example manual tracking:

// View item
window.NextAnalytics.trackViewItem({ id: '123', title: 'Product', price: 99.99 });
// Add to cart
window.NextAnalytics.trackAddToCart({ id: '123', quantity: 1 });
// Begin checkout
window.NextAnalytics.trackBeginCheckout();
// Purchase
window.NextAnalytics.trackPurchase(orderData);
providers: {
gtm: {
enabled: true,
blockedEvents: ['dl_test_event', 'internal_event'] // Optional
}
}

Options:

OptionTypeDescription
enabledbooleanEnable GTM integration
blockedEventsstring[]Events to exclude from GTM

Events are pushed to window.dataLayer and window.ElevarDataLayer.

See Google Tag Manager Setup for detailed configuration.

storeName: 'my-store', // CRITICAL for deduplication
analytics: {
providers: {
facebook: {
enabled: true,
settings: {
pixelId: 'YOUR_PIXEL_ID'
},
blockedEvents: [] // Optional
}
}
}

Options:

OptionTypeDescription
enabledbooleanEnable Facebook Pixel integration
settings.pixelIdstringRequired - Facebook Pixel ID
blockedEventsstring[]Events to exclude from Facebook

See Facebook Pixel Setup for event mapping and deduplication details.

providers: {
rudderstack: {
enabled: true,
blockedEvents: [] // Optional
}
}

Options:

OptionTypeDescription
enabledbooleanEnable RudderStack integration
blockedEventsstring[]Events to exclude from RudderStack

Events are mapped to Segment specification format.

See RudderStack Setup for event mapping details.

providers: {
custom: {
enabled: true,
settings: {
// Required
endpoint: 'https://api.yourapp.com/analytics',
// Optional headers
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
'X-Store-ID': 'store-123'
},
// Batching settings
batchSize: 10, // Events per batch (default: 10)
batchIntervalMs: 5000, // Max time before sending (default: 5000ms)
// Retry configuration
maxRetries: 3, // Retry attempts (default: 3)
retryDelayMs: 1000, // Initial retry delay (default: 1000ms)
// Transform function
transformFunction: (event) => {
event.app_version = '1.0.0';
return event;
}
},
blockedEvents: [] // Optional
}
}

Options:

OptionTypeDescription
enabledbooleanEnable custom webhook integration
settings.endpointstringRequired - Your webhook URL
settings.headersobjectCustom HTTP headers
settings.batchSizenumberEvents per batch (default: 10)
settings.batchIntervalMsnumberMax batch wait time (default: 5000ms)
settings.maxRetriesnumberRetry attempts on failure (default: 3)
settings.retryDelayMsnumberInitial retry delay with exponential backoff (default: 1000ms)
settings.transformFunctionfunctionTransform events before sending
blockedEventsstring[]Events to exclude from webhook

See Custom Webhook Setup for batching, retry logic, and implementation details.

Enable all providers simultaneously - each operates independently:

providers: {
gtm: { enabled: true },
facebook: { enabled: true, settings: { pixelId: 'xxx' } },
rudderstack: { enabled: true },
custom: { enabled: true, settings: { endpoint: 'https://...' } }
}

How it works:

  • Each event sent to ALL enabled providers
  • Providers operate independently (one failure doesn’t affect others)
  • Events always stored in NextDataLayer regardless of provider status
  • Debug mode shows which providers received each event
analytics: {
debug: true
}
const status = window.NextAnalytics.getStatus();
console.log(status);
// Output:
// {
// enabled: true,
// mode: 'auto',
// providers: ['GTM', 'Facebook', 'RudderStack'],
// eventsTracked: 15,
// debugMode: false
// }

Add ?ignore=true to URL:

https://yoursite.com?ignore=true

This disables ALL tracking for the entire session.

To clear ignore flag:

window.NextAnalyticsClearIgnore();
window.nextConfig = {
apiKey: 'your-api-key',
analytics: {
enabled: true,
mode: 'auto',
providers: {
gtm: { enabled: true }
}
}
};
window.nextConfig = {
apiKey: 'your-api-key',
storeName: 'my-store',
analytics: {
enabled: true,
mode: 'auto',
providers: {
gtm: { enabled: true },
facebook: {
enabled: true,
settings: { pixelId: 'YOUR_PIXEL_ID' }
}
}
}
};
window.nextConfig = {
apiKey: 'your-api-key',
analytics: {
enabled: true,
debug: true, // Enable debug logging
mode: 'auto',
providers: {
gtm: { enabled: false }, // Disable GTM in dev
custom: {
enabled: true,
settings: {
endpoint: 'http://localhost:3000/analytics',
headers: { 'X-Dev-Mode': 'true' }
}
}
}
}
};
window.nextConfig = {
apiKey: 'your-api-key',
storeName: 'enterprise-store',
analytics: {
enabled: true,
mode: 'auto',
providers: {
gtm: {
enabled: true,
blockedEvents: ['internal_test', 'dev_event']
},
facebook: {
enabled: true,
settings: { pixelId: 'PROD_PIXEL_ID' }
},
rudderstack: { enabled: true },
custom: {
enabled: true,
settings: {
endpoint: 'https://api.yourapp.com/analytics',
headers: {
'Authorization': 'Bearer YOUR_PRODUCTION_TOKEN',
'X-Environment': 'production',
'X-Region': 'US-WEST'
},
batchSize: 20,
batchIntervalMs: 3000,
maxRetries: 5,
transformFunction: (event) => {
// Add custom metadata
event.app_version = window.APP_VERSION;
event.environment = 'production';
event.region = 'us-west-1';
// Filter sensitive data
if (event.user_properties?.customer_phone) {
delete event.user_properties.customer_phone;
}
return event;
}
}
}
}
}
};
{
storeName: 'my-store', // Required for purchase deduplication
analytics: {
providers: {
facebook: { enabled: true, settings: { pixelId: 'xxx' } }
}
}
}

2. Use Auto Mode for Standard Implementations

Section titled “2. Use Auto Mode for Standard Implementations”
analytics: {
mode: 'auto' // Handles 90% of tracking automatically
}
analytics: {
debug: process.env.NODE_ENV === 'development'
}
providers: {
gtm: {
enabled: true,
blockedEvents: ['internal_test', 'dev_event', 'debug_event']
}
}

5. Use Transform Functions for Custom Data

Section titled “5. Use Transform Functions for Custom Data”
custom: {
settings: {
transformFunction: (event) => {
event.custom_field = getCustomData();
return event;
}
}
}