Introduction
ViewContent events track when users view product pages, blog posts, or other content on your website. This guide explains when and how to implement ViewContent events effectively.
When to Fire ViewContent
Fire ViewContent events when:
- Product Pages: User views a product detail page
- Blog Posts: User views an article or blog post
- Content Pages: User views any important content
- Category Pages: User views a category or collection page
Typically fire ViewContent once per page view, when the page loads or content is displayed.
Parameter Structure
ViewContent events should include:
- content_ids (required): Array of content/product IDs
- content_type (required): Type of content (e.g., "product", "article")
- content_name (optional): Name or title of the content
- content_category (optional): Category of the content
- value (optional): Value or price of the content
- currency (optional): Currency code (required if value is provided)
Implementation Example
// On product page
document.addEventListener('DOMContentLoaded', () => {
const userData = {
country: "US"
// Add email, phone if available
};
st('track', 'ViewContent', {
content_ids: ['product-123'],
content_type: 'product',
content_name: 'Amazing Product',
content_category: 'Electronics',
value: 99.99,
currency: 'USD'
}, userData);
});
Content IDs
Content IDs should be:
- Unique Identifiers: Unique IDs for each content item
- String Format: Use strings, not numbers
- Array Format: Always use an array, even for single items
// Single product
content_ids: ['product-123']
// Multiple products (for category pages)
content_ids: ['product-123', 'product-456', 'product-789']
Value Calculation
For ViewContent events, value typically represents:
- Product Price: The price of the product being viewed
- Content Value: Any meaningful value associated with the content
- Optional: Value is optional for ViewContent, but recommended for products
Best Practices
- Fire on Page Load: Fire ViewContent when page loads or content is displayed
- Include Content IDs: Always include content_ids for proper tracking
- Use Meaningful Names: Include content_name for better reporting
- Consistent Formatting: Use consistent IDs and naming conventions
Summary
ViewContent events track content views. Include content_ids, content_type, and optionally value, currency, and content_name. Fire when users view products, articles, or other important content.