Context Tags Reference
Context tags allow you to pass dynamic data from your website to your AI workflows, enabling personalized and context-aware chat responses.
What Are Context Tags?
Context tags are dynamic variables that automatically populate with real-time data from your website. When a user sends a chat message, N8.Chat includes relevant context tags in the webhook payload, allowing your AI to provide informed, personalized responses.
Example Use Cases
- -Show product recommendations based on current cart contents
- -Provide order status updates using the customers order ID
- -Reference the current page URL to give page-specific help
- -Personalize greetings using the customers name
- -Offer mobile-specific support based on device type
General Context Tags
These tags are available on all platforms (WordPress, Shopify, and custom integrations):
| Tag | Description | Example Value |
|---|---|---|
{{page_url}} | Current page URL | https://example.com/products/shoes |
{{page_title}} | Current page title | Running Shoes - My Store |
{{page_path}} | URL path without domain | /products/shoes |
{{referrer}} | Previous page URL | https://google.com |
{{user_name}} | Logged-in users display name | John Doe |
{{user_email}} | Logged-in users email | john@example.com |
{{user_id}} | Logged-in users unique ID | 12345 |
{{session_id}} | Unique session identifier | sess_abc123xyz789 |
{{device_type}} | Device type | mobile | tablet | desktop |
{{browser}} | Browser name | Chrome |
{{language}} | Browser language | en-US |
{{timezone}} | Users timezone | America/New_York |
{{timestamp}} | Current timestamp (ISO 8601) | 2025-01-15T10:30:00Z |
WooCommerce Tags
When N8.Chat is installed on a WordPress site with WooCommerce, these additional tags become available:
| Tag | Description | Example Value |
|---|---|---|
{{cart_total}} | Current cart total (formatted) | $129.99 |
{{cart_total_raw}} | Cart total as number | 129.99 |
{{cart_items}} | Number of items in cart | 3 |
{{cart_contents}} | JSON array of cart items | [{ name, qty, price }] |
{{cart_currency}} | Cart currency code | USD |
{{order_id}} | Most recent order ID | WC-12345 |
{{order_status}} | Recent order status | processing | shipped | delivered |
{{product_id}} | Current product ID (product pages) | 567 |
{{product_name}} | Current product name | Premium Headphones |
{{product_price}} | Current product price | $89.99 |
{{product_sku}} | Current product SKU | HP-PRO-001 |
{{product_category}} | Product category | Electronics |
{{product_stock}} | Stock quantity | 15 |
{{customer_orders_count}} | Total orders by customer | 5 |
{{customer_total_spent}} | Total spent by customer | $1,250.00 |
Shopify Tags
When N8.Chat is installed on Shopify, these platform-specific tags are available:
| Tag | Description | Example Value |
|---|---|---|
{{cart_token}} | Shopify cart token | c1-abc123def456 |
{{shop_domain}} | Shopify store domain | mystore.myshopify.com |
{{shop_name}} | Store display name | My Awesome Store |
{{collection_handle}} | Current collection handle | summer-sale |
{{collection_title}} | Collection display title | Summer Sale |
{{product_handle}} | Product URL handle | premium-headphones |
{{variant_id}} | Product variant ID | 39876543210987 |
{{variant_title}} | Selected variant name | Black / Large |
{{customer_id}} | Shopify customer ID | 3456789012345 |
{{customer_tags}} | Customer tags array | ["vip", "wholesale"] |
{{discount_code}} | Applied discount code | SUMMER20 |
Custom Tags
You can define custom context tags using the JavaScript API to pass any data from your website:
JavaScript API - Custom Context:
// Set custom context data
window.N8Chat.setContext({
custom_field: 'any value',
user_tier: 'premium',
subscription_plan: 'enterprise',
last_purchase_date: '2025-01-10',
preferred_language: 'en',
account_age_days: 365
});
// Update a single context value
window.N8Chat.updateContext('promotion_code', 'NEWYEAR25');
// Get current context
const context = window.N8Chat.getContext();
console.log(context);Note: Custom context values are merged with automatic context tags and sent with every chat message.
Usage Examples
Example 1: Cart Abandonment Recovery
Use cart context tags to create personalized cart recovery messages:
n8n AI System Prompt:
You are a helpful shopping assistant for our store.
Current customer context:
- Customer name: {{user_name}}
- Cart items: {{cart_items}} items
- Cart total: {{cart_total}}
- Current page: {{page_title}}
If the customer has items in their cart, gently offer to help
them complete their purchase. Mention any current promotions.Example 2: Order Status Lookup
Automatically fetch order details using the order ID in n8n:
n8n HTTP Request Node:
URL: https://yourstore.com/wp-json/wc/v3/orders/{{$json.context.order_id}}
Method: GET
Authentication: Basic Auth (WooCommerce API keys)
// Response can be used to tell the customer:
// - Order status
// - Shipping tracking
// - Estimated delivery dateExample 3: Product Recommendations
Recommend related products based on the current product page:
AI Prompt with Context:
The customer is viewing: {{product_name}}
Product category: {{product_category}}
Product price: {{product_price}}
Product SKU: {{product_sku}}
Based on this product, recommend 3 complementary items from our
catalog that would enhance their purchase. Focus on items in a
similar price range.Example 4: VIP Customer Treatment
Provide special treatment for high-value customers:
Conditional Logic in n8n:
// Check if customer is a VIP (n8n IF node)
const totalSpent = parseFloat($json.context.customer_total_spent);
const ordersCount = parseInt($json.context.customer_orders_count);
const isVIP = totalSpent > 1000 || ordersCount > 10;
// Use different AI prompts for VIP vs regular customers
if (isVIP) {
return { prompt: "You are a premium concierge assistant..." };
} else {
return { prompt: "You are a helpful customer service agent..." };
}Accessing Context in n8n
Context tags are sent in the webhook request body. Access them using n8n expression syntax:
Basic Access
{{ $json.context.page_url }}Conditional Logic
{{ $json.context.cart_items > 0 ? 'You have items' : 'Cart is empty' }}Null Safety
{{ $json.context.user_name || 'Guest' }}Full Webhook Payload
{
"message": "Help me with my order",
"context": {
"page_url": "https://example.com/my-account",
"page_title": "My Account",
"user_name": "John Doe",
"user_email": "john@example.com",
"cart_total": "$129.99",
"cart_items": 3,
"order_id": "WC-12345",
"device_type": "mobile",
"timestamp": "2025-01-15T10:30:00Z"
},
"session": {
"id": "sess_abc123",
"started_at": "2025-01-15T10:00:00Z"
}
}