@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
462 lines (455 loc) • 17.1 kB
JavaScript
/**
* E-commerce Optimization Workflow Example
* Complete multi-step workflow for e-commerce optimization
*/
export const ecommerceOptimizationComplete = {
id: 'tpl_ecommerce_optimization',
name: 'E-commerce Optimization Workflow',
description: 'Complete workflow for optimizing e-commerce checkout with A/B testing and personalization',
version: '1.0.0',
type: 'user',
platform: 'web',
author: 'orchestration.bible@optimizely.com',
template_format_version: 2,
parameters: {
project_id: {
type: 'string',
required: true,
description: 'Web Experimentation project ID'
},
checkout_url: {
type: 'string',
required: true,
description: 'Checkout page URL pattern',
default: 'https://shop.example.com/checkout'
},
cart_threshold: {
type: 'number',
required: false,
default: 100,
description: 'Cart value threshold for high-value customers'
}
},
steps: [
// Create custom attributes
{
id: 'create_cart_value_attribute',
type: 'template',
name: 'Create Cart Value Attribute',
template: {
entity_type: 'attribute',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
key: 'cart_value',
name: 'Cart Value',
description: 'Current cart value in dollars',
type: 'number'
}
}
},
{
id: 'create_customer_type_attribute',
type: 'template',
name: 'Create Customer Type Attribute',
template: {
entity_type: 'attribute',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
key: 'customer_type',
name: 'Customer Type',
description: 'Type of customer (new, returning, vip)',
type: 'list',
list_type: 'string',
values: ['new', 'returning', 'vip']
}
}
},
// Create events
{
id: 'create_checkout_started_event',
type: 'template',
name: 'Create Checkout Started Event',
template: {
entity_type: 'event',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Checkout Started',
key: 'checkout_started',
event_type: 'custom',
category: 'other'
}
}
},
{
id: 'create_purchase_event',
type: 'template',
name: 'Create Purchase Completed Event',
template: {
entity_type: 'event',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Purchase Completed',
key: 'purchase_completed',
event_type: 'custom',
category: 'purchase'
}
}
},
{
id: 'create_checkout_abandoned_event',
type: 'template',
name: 'Create Checkout Abandoned Event',
template: {
entity_type: 'event',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Checkout Abandoned',
key: 'checkout_abandoned',
event_type: 'custom',
category: 'other'
}
}
},
// Create audiences
{
id: 'create_high_value_audience',
type: 'template',
name: 'Create High Value Customer Audience',
template: {
entity_type: 'audience',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'High Value Customers',
key: 'high_value_customers',
conditions: [
{
field: 'cart_value',
match: 'gt',
value: '${cart_threshold}'
}
]
}
},
depends_on: ['create_cart_value_attribute']
},
{
id: 'create_returning_customer_audience',
type: 'template',
name: 'Create Returning Customer Audience',
template: {
entity_type: 'audience',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Returning Customers',
key: 'returning_customers',
conditions: [
{
field: 'customer_type',
match: 'list_contains',
value: 'returning'
}
]
}
},
depends_on: ['create_customer_type_attribute']
},
// Create pages
{
id: 'create_checkout_page',
type: 'template',
name: 'Create Checkout Page',
template: {
entity_type: 'page',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Checkout Page',
key: 'checkout_page',
conditions: [
{
match_type: 'substring',
value: '${checkout_url}'
}
]
}
}
},
// Create campaign
{
id: 'create_campaign',
type: 'template',
name: 'Create Checkout Optimization Campaign',
template: {
entity_type: 'campaign',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Checkout Optimization Campaign',
status: 'active'
}
}
},
// Create A/B test experiment
{
id: 'create_checkout_ab_test',
type: 'template',
name: 'Create Checkout A/B Test',
template: {
entity_type: 'experiment',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Checkout Flow A/B Test',
campaign_id: '${create_campaign.entity_id}',
page_ids: ['${create_checkout_page.entity_id}'],
audience: {
ref: {
id: null // Everyone
}
},
traffic_allocation: 10000,
metrics: [
{
event_id: '${create_purchase_event.entity_id}',
scope: 'visitor',
winning_direction: 'increasing'
},
{
event_id: '${create_checkout_abandoned_event.entity_id}',
scope: 'visitor',
winning_direction: 'decreasing'
}
],
variations: [
{
name: 'Control',
weight: 5000,
actions: []
},
{
name: 'Simplified Checkout',
weight: 5000,
actions: [
{
page_id: '${create_checkout_page.entity_id}',
changes: [
{
type: 'custom_code',
value: `// Simplified checkout flow
document.addEventListener('DOMContentLoaded', function() {
// Remove optional fields
const optionalFields = document.querySelectorAll('.optional-field');
optionalFields.forEach(field => field.style.display = 'none');
// Combine shipping and billing
const billingSection = document.querySelector('#billing-address');
if (billingSection) {
billingSection.innerHTML = '<label><input type="checkbox" checked> Same as shipping address</label>';
}
// Add progress indicator
const progress = document.createElement('div');
progress.className = 'checkout-progress';
progress.innerHTML = '<div class="progress-bar" style="width: 33%"></div>';
document.querySelector('.checkout-header').appendChild(progress);
});`
}
]
}
]
}
]
}
},
depends_on: ['create_campaign', 'create_checkout_page', 'create_purchase_event', 'create_checkout_abandoned_event']
},
// Create personalization for high-value customers
{
id: 'create_high_value_personalization',
type: 'template',
name: 'Create High Value Customer Experience',
template: {
entity_type: 'experiment',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'High Value Customer VIP Checkout',
campaign_id: '${create_campaign.entity_id}',
page_ids: ['${create_checkout_page.entity_id}'],
audience: {
ref: {
id: '${create_high_value_audience.entity_id}'
}
},
metrics: [
{
event_id: '${create_purchase_event.entity_id}',
scope: 'visitor',
winning_direction: 'increasing'
}
],
variations: [
{
name: 'VIP Checkout Experience',
weight: 10000,
actions: [
{
page_id: '${create_checkout_page.entity_id}',
changes: [
{
type: 'custom_code',
value: `// VIP checkout experience
document.addEventListener('DOMContentLoaded', function() {
// Add VIP benefits banner
const vipBanner = document.createElement('div');
vipBanner.className = 'vip-checkout-banner';
vipBanner.innerHTML = \`
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 15px; margin-bottom: 20px; border-radius: 8px;">
<h3>🌟 VIP Customer Benefits Applied</h3>
<ul style="margin: 10px 0;">
<li>Free Express Shipping</li>
<li>Priority Customer Support</li>
<li>Extended 90-day Returns</li>
</ul>
</div>
\`;
const checkoutForm = document.querySelector('.checkout-form');
checkoutForm.insertBefore(vipBanner, checkoutForm.firstChild);
// Auto-select express shipping
const expressShipping = document.querySelector('input[value="express"]');
if (expressShipping) {
expressShipping.checked = true;
expressShipping.closest('.shipping-option').querySelector('.price').textContent = 'FREE';
}
});`
}
]
}
]
}
]
}
},
depends_on: ['create_campaign', 'create_checkout_page', 'create_high_value_audience', 'create_purchase_event']
},
// Create extension for tracking
{
id: 'create_tracking_extension',
type: 'template',
name: 'Create Enhanced Tracking Extension',
template: {
entity_type: 'extension',
mode: 'template',
operation: 'create',
template_data: {
project_id: '${project_id}',
name: 'Enhanced E-commerce Tracking',
key: 'enhanced_ecommerce_tracking',
description: 'Tracks detailed checkout funnel metrics',
extension_point: 'project_javascript',
enabled: true,
html: '',
css: '',
javascript: `// Enhanced E-commerce Tracking
(function() {
// Track checkout steps
window.optimizely = window.optimizely || [];
// Track when checkout starts
if (window.location.href.includes('/checkout')) {
window.optimizely.push({
type: "event",
eventName: "checkout_started",
tags: {
value: window.cartValue || 0,
items: window.cartItems || 0
}
});
}
// Track form field interactions
document.addEventListener('focus', function(e) {
if (e.target.matches('.checkout-form input, .checkout-form select')) {
window.optimizely.push({
type: "event",
eventName: "checkout_field_interaction",
tags: {
field_name: e.target.name,
field_type: e.target.type
}
});
}
}, true);
// Track checkout abandonment
window.addEventListener('beforeunload', function(e) {
if (!window.purchaseCompleted && window.location.href.includes('/checkout')) {
window.optimizely.push({
type: "event",
eventName: "checkout_abandoned",
tags: {
last_field: document.activeElement.name || 'unknown',
time_on_page: Math.round((Date.now() - window.pageLoadTime) / 1000)
}
});
}
});
})();`
}
}
}
],
outputs: {
campaign_id: {
value: '${create_campaign.entity_id}',
description: 'Checkout optimization campaign ID'
},
ab_test_id: {
value: '${create_checkout_ab_test.entity_id}',
description: 'Main A/B test experiment ID'
},
vip_experience_id: {
value: '${create_high_value_personalization.entity_id}',
description: 'VIP personalization experiment ID'
}
},
best_practices: [
'Track multiple metrics including micro-conversions',
'Use custom attributes to segment audiences dynamically',
'Create extensions for advanced tracking needs',
'Start with simple A/B tests before complex personalization',
'Use meaningful event names that align with analytics tools',
'Test JavaScript code thoroughly before deployment'
],
common_mistakes: [
{
mistake: 'Not tracking micro-conversions in the funnel',
example: 'Only tracking final purchase without intermediate steps',
solution: 'Track checkout_started, field interactions, and abandonment'
},
{
mistake: 'Hardcoding audience conditions instead of using attributes',
example: 'Using specific cart values like "exactly $150"',
solution: 'Use attributes with comparison operators for flexibility'
},
{
mistake: 'Creating audiences before their required attributes',
example: 'Referencing cart_value before creating the attribute',
solution: 'Always create attributes first, then audiences'
}
]
};
//# sourceMappingURL=EcommerceOptimizationExample.js.map