1. Sign up for an account and get your API key from the dashboard.
2. Add the SDK to your site:
<script src="https://optimize.netwrck.com/sdk.js"
data-optimize-key="YOUR_API_KEY"></script>Create experiments via the dashboard or API:
curl -X POST https://optimize.netwrck.com/api/experiments \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "CTA Test", "variants": ["control", "variant_a", "variant_b"]}'optimize.getVariant(experimentId, function(variant) {
console.log('Assigned to:', variant);
});optimize.convert(experimentId, value, goalName);optimize.activate(experimentId, {
'variant_a': {
'.headline': { text: 'New Headline' },
'.cta': { style: { backgroundColor: 'green' } }
}
});Neural contextual bandits that learn which content converts best for each user segment in real-time.
Rank actions based on user context. Returns actions sorted by predicted conversion probability:
optimize.personalize('hero-cta', {
context: {
device: 'mobile',
referrer: 'google',
returning_user: true
},
actions: [
{ id: 'free-trial', features: { urgency: 'low' } },
{ id: 'book-demo', features: { urgency: 'high' } },
{ id: 'see-pricing', features: { urgency: 'medium' } }
]
}, function(result) {
// result.ranking = actions sorted by probability
// result.event_id = use for reward tracking
showCTA(result.ranking[0]);
});When the user converts, send a reward to train the model:
// After user clicks CTA or converts
optimize.personalizeReward(eventId, 1.0);
// Or use the last personalization event automatically
optimize.personalizeReward(null, 1.0);optimize.getBestAction('hero-cta', context, actions, function(bestAction, eventId) {
displayAction(bestAction);
// Track when user converts
button.onclick = function() {
optimize.personalizeReward(eventId, 1);
};
});// Automatically send reward when user clicks any matching element
optimize.autoReward('.cta-button', 1.0);For automatic optimization using Thompson Sampling:
// Get best arm
optimize.selectArm(banditId, function(arm) {
showVariant(arm);
});
// Record reward (e.g., on conversion)
optimize.reward(banditId, 1);Optimize provides first-class Shopify support with automatic add-to-cart tracking, purchase tracking, and specialized A/B testing helpers.
Add the SDK to your theme.liquid file, just before the closing </head> tag:
<script src="https://optimize.netwrck.com/sdk.js"
data-optimize-key="YOUR_API_KEY"></script>
<script>
// Initialize Shopify integration
document.addEventListener('DOMContentLoaded', function() {
optimize.initShopify();
});
</script>Once initialized, Optimize automatically tracks:
optimize.testAddToCart(experimentId, {
'variant_a': {
text: 'Add to Cart',
style: { backgroundColor: '#000' }
},
'variant_b': {
text: 'Buy Now - Free Shipping!',
style: { backgroundColor: '#22c55e', fontWeight: 'bold' }
}
});// Test with product context automatically included
optimize.testProduct(experimentId, {
'variant_a': {
'.product-title': { style: { fontSize: '28px' } }
},
'variant_b': {
'.product-title': { style: { fontSize: '36px', color: '#1a1a1a' } },
'.product-badge': { text: 'BEST SELLER', show: true }
}
});optimize.testPrice(experimentId, {
'variant_a': {
format: '${price}'
},
'variant_b': {
format: 'Only ${price} - Save 20%!',
style: { color: '#dc2626', fontWeight: 'bold' }
}
});Add this to your checkout thank you page (or use Shopify's Additional Scripts):
<script>
// Shopify provides order data on thank you page
{% if first_time_accessed %}
optimize.trackPurchase({
total_price: {{ checkout.total_price }},
order_id: '{{ order.name }}'
});
{% endif %}
</script>If you need manual control over tracking:
// Manual add to cart tracking
optimize.trackAddToCart({
price: 2999, // price in cents
product_id: '12345'
});
// Get current cart data
optimize.getCart(function(cart) {
console.log('Cart total:', cart.total_price / 100);
});// Listen for add to cart events
document.addEventListener('optimize:addtocart', function(e) {
console.log('Product added:', e.detail);
});Include your API key in the X-API-Key header or as api_key query parameter.
We use a two-proportion z-test to determine statistical significance at 95% confidence. Results show: