Context Web Object
Overview
The context web object captures browser environment data for events collected through JavaScript implementations. Most context data (URL, environment) is collected automatically by the DATA Reshape script. Manual implementation is only needed for SPA applications or when you want to specify page_type for more granular analytics.
Properties
- url — collected automatically for standard websites. Required only for SPA applications where URL changes don't trigger automatic page context updates.
- page_type — categorizes the current page for analytics (e.g.
product,category,cart,checkout,home,blog,contact). Free-form string, use consistent naming across your site. - environment —
prodfor live data,devfor testing. Events sent withdevare logged but not processed.
Complete Reference
context object
url string required-if-applicable
Collected automatically for standard websites. Required only for SPA applications where URL changes don't trigger automatic page context updates.
url:"https://shop.example.com/products/laptop?color=silver&storage=512gb&utm_source=google"
URL Parameter Sensitivity: Be mindful of sensitive information in URLs. Query parameters may contain personal identifiers, session tokens, or private information that should be handled according to privacy regulations.
page_type string recommended
Type of page (product, home ...)
page_type: "product"
environment string recommended
Allowed values: prod, dev
environment: "prod"
Examples
- Standard Website
- SPA Application
- Development
{
"page_type": "product",
"environment": "prod"
}
URL is collected automatically. Only page_type and environment need to be specified.
{
"url": "https://app.example.com/dashboard/analytics?date_range=30d",
"page_type": "dashboard",
"environment": "prod"
}
For SPA applications, url must be provided manually on each route change since the browser URL doesn't update automatically.
{
"page_type": "product",
"environment": "dev"
}
Events with dev environment are logged for debugging but not processed or forwarded to destinations.
SPA Implementation
For Single Page Applications, push a new event with updated context on each route change:
// On each SPA route change, push a new event with the current route URL
window.reshape = window.reshape || [];
reshape.push({
event: {
name: "page_viewed"
},
context: {
url: currentRouteUrl, // Current route URL from your framework's router
page_type: "dashboard",
environment: "prod"
}
});
Best Practices
- Consistent page types — use a standardized naming convention for
page_typeacross your site - SPA route tracking — ensure context updates on every significant route change
- Use
devfor testing — setenvironmenttodevduring integration to validate events without processing - URL sensitivity — be mindful of sensitive information in URL parameters (session tokens, personal identifiers); consider filtering before tracking