Complete guide to integrating Loyalty.lt with your Shopify store
Connect Your Store
// Automatic configuration via Shopify App // No code required - handled by the app interface
Configure Point Rules
{ "earning_rules": { "purchase": { "rate": 1, "per_dollar": true, "minimum_order": 10 }, "signup": { "points": 100, "one_time": true }, "referral": { "points": 500, "referee_bonus": 250 } } }
Set Redemption Options
{ "redemption_rules": { "discount": { "rate": 100, "per_dollar": true, "minimum_points": 500 }, "free_shipping": { "points_cost": 200, "minimum_order": 50 } } }
// Shopify webhook endpoints const webhooks = { "orders/create": "https://api.loyalty.lt/webhooks/shopify/order-created", "orders/updated": "https://api.loyalty.lt/webhooks/shopify/order-updated", "customers/create": "https://api.loyalty.lt/webhooks/shopify/customer-created", "customers/update": "https://api.loyalty.lt/webhooks/shopify/customer-updated" };
{ "field_mapping": { "shopify_customer_id": "external_id", "email": "email", "first_name": "first_name", "last_name": "last_name", "phone": "phone", "birthday": "birth_date", "accepts_marketing": "marketing_consent" } }
<!-- Shopify Liquid template --> {% if customer %} <div class="loyalty-widget" data-customer-id="{{ customer.id }}"> <h3>Welcome to our Loyalty Program!</h3> <p>You've earned {{ customer.metafields.loyalty.points }} points</p> </div> {% endif %}
<!-- Order confirmation page --> {% if order.customer %} <div class="points-earned"> <h4>🎉 You earned {{ order.total_price | times: 1 | round }} points!</h4> <p>Total points: {{ customer.metafields.loyalty.points }}</p> </div> {% endif %}
// Award bonus points LoyaltySDK.awardPoints({ customerId: customer.id, points: 50, reason: 'Product review', orderId: order.id });
<!-- Cart page --> {% if customer and customer.metafields.loyalty.points > 0 %} <div class="loyalty-redemption"> <h4>Use {{ customer.metafields.loyalty.points }} points</h4> <button onclick="applyLoyaltyDiscount()">Apply ${{ customer.metafields.loyalty.points | divided_by: 100 }} discount</button> </div> {% endif %}
function applyLoyaltyDiscount() { LoyaltySDK.redeemPoints({ customerId: customer.id, points: pointsToRedeem, orderId: cart.token, onSuccess: function(discount) { // Apply discount code to cart applyShopifyDiscount(discount.code); } }); }
// Customer metafields for loyalty data { "loyalty": { "points": 1250, "tier": "gold", "lifetime_spent": 2500, "referrals": 3, "last_activity": "2024-01-15" } }
// Loyalty impact report const report = await LoyaltySDK.getReport({ type: 'loyalty_impact', dateRange: '30d', metrics: ['revenue', 'orders', 'redemptions'] });
// Customer segmentation const segments = await LoyaltySDK.getCustomerSegments({ criteria: { points_range: [1000, 5000], tier: 'gold', last_purchase: '30d' } });
<!-- Add to theme.liquid --> <div id="loyalty-widget" data-shop-id="{{ shop.permanent_domain }}" data-customer-id="{% if customer %}{{ customer.id }}{% endif %}"> </div> <script src="https://cdn.loyalty.lt/shopify-widget.js"></script>
<!-- Product page points preview --> {% assign points_earned = product.price | times: 1 | round %} <div class="points-preview"> <span>Earn {{ points_earned }} points with this purchase</span> </div>
<!-- Loyalty balance --> {{ customer | loyalty_points }} <!-- Points earning preview --> {{ product.price | points_preview }} <!-- Tier status --> {{ customer | loyalty_tier }} <!-- Redemption options --> {% loyalty_redemptions customer %}
Points Not Awarded
// Debug point calculation LoyaltySDK.debug.calculatePoints({ orderId: 'order_id', customerId: 'customer_id' });
Redemption Failures
// Debug redemption LoyaltySDK.debug.testRedemption({ customerId: 'customer_id', points: 500 });
Widget Not Loading
<!-- Debug widget loading --> <script> LoyaltySDK.debug.checkWidget({ shopId: 'your-shop-id', placement: 'theme' }); </script>
Test Customer Registration
// Create test customer const testCustomer = { email: 'test@example.com', first_name: 'Test', last_name: 'Customer' }; LoyaltySDK.test.registerCustomer(testCustomer);
Test Points Earning
// Simulate order LoyaltySDK.test.simulateOrder({ customerId: 'test_customer_id', amount: 100, items: ['product_1', 'product_2'] });
Test Redemption
// Test point redemption LoyaltySDK.test.redeemPoints({ customerId: 'test_customer_id', points: 500 });
// Cache customer loyalty data const cache = { duration: 300, // 5 minutes keys: ['points', 'tier', 'available_rewards'] }; LoyaltySDK.configure({ cache: cache, lazy_load: true });
<!-- Lazy load loyalty widget --> <script async defer src="https://cdn.loyalty.lt/shopify-widget.js"></script> <!-- Critical CSS for loyalty elements --> <style> .loyalty-widget { display: none; } .loyalty-widget.loaded { display: block; } </style>
// Webhook verification const crypto = require('crypto'); function verifyWebhook(payload, signature) { const hmac = crypto.createHmac('sha256', process.env.LOYALTY_WEBHOOK_SECRET); hmac.update(payload); const calculatedSignature = hmac.digest('base64'); return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(calculatedSignature) ); }
// Import existing customer data const migrationData = { customers: [ { shopify_id: 'customer_123', email: 'customer@example.com', points: 1500, tier: 'gold', transactions: [] } ] }; LoyaltySDK.migrate.importData(migrationData);
// Export loyalty data const exportData = await LoyaltySDK.export.customerData({ format: 'csv', fields: ['email', 'points', 'tier', 'lifetime_value'] });
// Configure multiple Shopify stores LoyaltySDK.configure({ stores: [ { id: 'store1', domain: 'store1.myshopify.com' }, { id: 'store2', domain: 'store2.myshopify.com' } ], shared_loyalty: true });
// Custom loyalty rules LoyaltySDK.extend({ customRule: function(order, customer) { // Custom point calculation logic if (customer.tier === 'vip') { return order.total * 2; // Double points for VIP } return order.total; } });
// Automated campaigns LoyaltySDK.automation.create({ trigger: 'birthday', action: 'award_points', points: 100, message: 'Happy Birthday! Here are 100 bonus points!' });