Feature Reference

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):

TagDescriptionExample Value
{{page_url}}Current page URLhttps://example.com/products/shoes
{{page_title}}Current page titleRunning Shoes - My Store
{{page_path}}URL path without domain/products/shoes
{{referrer}}Previous page URLhttps://google.com
{{user_name}}Logged-in users display nameJohn Doe
{{user_email}}Logged-in users emailjohn@example.com
{{user_id}}Logged-in users unique ID12345
{{session_id}}Unique session identifiersess_abc123xyz789
{{device_type}}Device typemobile | tablet | desktop
{{browser}}Browser nameChrome
{{language}}Browser languageen-US
{{timezone}}Users timezoneAmerica/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:

TagDescriptionExample Value
{{cart_total}}Current cart total (formatted)$129.99
{{cart_total_raw}}Cart total as number129.99
{{cart_items}}Number of items in cart3
{{cart_contents}}JSON array of cart items[{ name, qty, price }]
{{cart_currency}}Cart currency codeUSD
{{order_id}}Most recent order IDWC-12345
{{order_status}}Recent order statusprocessing | shipped | delivered
{{product_id}}Current product ID (product pages)567
{{product_name}}Current product namePremium Headphones
{{product_price}}Current product price$89.99
{{product_sku}}Current product SKUHP-PRO-001
{{product_category}}Product categoryElectronics
{{product_stock}}Stock quantity15
{{customer_orders_count}}Total orders by customer5
{{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:

TagDescriptionExample Value
{{cart_token}}Shopify cart tokenc1-abc123def456
{{shop_domain}}Shopify store domainmystore.myshopify.com
{{shop_name}}Store display nameMy Awesome Store
{{collection_handle}}Current collection handlesummer-sale
{{collection_title}}Collection display titleSummer Sale
{{product_handle}}Product URL handlepremium-headphones
{{variant_id}}Product variant ID39876543210987
{{variant_title}}Selected variant nameBlack / Large
{{customer_id}}Shopify customer ID3456789012345
{{customer_tags}}Customer tags array["vip", "wholesale"]
{{discount_code}}Applied discount codeSUMMER20

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 date

Example 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"
  }
}