Shopify Integration Guide
Learn how to integrate DaisyChain with your Shopify store.
Overview
Integration Features
Referral Tracking
Track referrals and conversions
Revenue Attribution
Monitor referral revenue and ROI
Setup
1. Create Shopify App
First, set up a new Shopify app using the Shopify CLI:
# Install Shopify CLI
npm install -g @shopify/cli @shopify/app
# Create new app
shopify app create node
# Add DaisyChain SDK
npm install @daisychain/sdk
2. Configure App
// app/server.js
const express = require('express');
const { DaisyChain } = require('@daisychain/sdk');
const { verifyHmac } = require('./utils/shopify');
const app = express();
const client = new DaisyChain({
apiKey: process.env.DAISYCHAIN_API_KEY
});
// Verify Shopify webhooks
const verifyShopifyWebhook = (req, res, next) => {
const hmac = req.headers['x-shopify-hmac-sha256'];
const verified = verifyHmac(hmac, req.body, process.env.SHOPIFY_SECRET);
if (!verified) return res.status(401).send('Invalid webhook');
next();
};
// Handle orders
app.post('/webhooks/orders/create', verifyShopifyWebhook, async (req, res) => {
const order = req.body;
const referralCode = order.note_attributes.find(
attr => attr.name === 'referral_code'
)?.value;
if (referralCode) {
try {
await client.submitReferral({
referrerIdentifier: referralCode,
customerId: order.customer.id,
orderId: order.id,
orderAmount: parseFloat(order.total_price),
metadata: {
platform: 'shopify',
shop: req.headers['x-shopify-shop-domain']
}
});
} catch (error) {
console.error('Failed to track referral:', error);
}
}
res.sendStatus(200);
});
3. Add Referral Field
Add a referral code field to your checkout:
{% comment %}
sections/checkout.liquid
{% endcomment %}
<div class="referral-field">
<label for="referral-code">Referral Code</label>
<input
type="text"
id="referral-code"
name="attributes[referral_code]"
placeholder="Enter referral code"
>
</div>
<script>
const referralField = document.getElementById('referral-code');
const referralCode = new URLSearchParams(window.location.search).get('ref');
if (referralCode) {
referralField.value = referralCode;
}
</script>
Testing
Test Mode
Enable test mode during development:
const client = new DaisyChain({
apiKey: process.env.DAISYCHAIN_API_KEY,
testMode: true
});
Test Orders
- Create a test referral code
- Place a test order using the code
- Verify the referral is tracked
- Check webhook delivery
- Test refund handling
Best Practices
Security
- • Verify webhook signatures
- • Use environment variables
- • Validate inputs
Error Handling
- • Log API errors
- • Implement retries
- • Monitor failures
Troubleshooting
Common Issues
Webhook Issues
- • Check webhook URLs
- • Verify HMAC signatures
- • Monitor webhook logs
API Issues
- • Validate API key
- • Check rate limits
- • Review error logs
Support
Need help with your Shopify integration?
- Check our API Reference
- Join our Discord Community
- Email support@daisychain.la