Integration Guides
DaisyChain can be integrated with any platform or framework. Here are guides for common integration scenarios.
E-commerce Platforms
Shopify
// In your Shopify app
import { DaisyChain } from '@daisychain/sdk';
const client = new DaisyChain({
apiKey: DAISYCHAIN_API_KEY,
storeId: STORE_ID
});
// Listen for order creation
app.post('/webhooks/orders/create', async (req, res) => {
const order = req.body;
if (order.referral_code) {
await client.submitReferral({
referrerIdentifier: order.referral_code,
customerId: order.customer.id,
orderId: order.id,
orderAmount: order.total_price,
metadata: {
platform: 'shopify',
products: order.line_items.map(item => item.product_id)
}
});
}
res.sendStatus(200);
});
WooCommerce
// In your WordPress theme or plugin
function track_woocommerce_referral($order_id) {
$order = wc_get_order($order_id);
$referral_code = get_post_meta($order_id, 'referral_code', true);
if ($referral_code) {
$data = array(
'referrerIdentifier' => $referral_code,
'customerId' => $order->get_customer_id(),
'orderId' => $order_id,
'orderAmount' => $order->get_total(),
'metadata' => array(
'platform' => 'woocommerce',
'products' => array_map(function($item) {
return $item->get_product_id();
}, $order->get_items())
)
);
wp_remote_post('https://api.daisychain.la/api/referrals', array(
'headers' => array(
'X-API-Key' => DAISYCHAIN_API_KEY,
'X-Store-ID' => STORE_ID,
'Content-Type' => 'application/json'
),
'body' => json_encode($data)
));
}
}
add_action('woocommerce_order_status_completed', 'track_woocommerce_referral');
SaaS Platforms
Stripe Integration
// In your Node.js backend
import Stripe from 'stripe';
import { DaisyChain } from '@daisychain/sdk';
const stripe = new Stripe(STRIPE_SECRET_KEY);
const daisychain = new DaisyChain({
apiKey: DAISYCHAIN_API_KEY,
storeId: STORE_ID
});
// Handle Stripe webhook
app.post('/webhook/stripe', async (req, res) => {
const event = stripe.webhooks.constructEvent(
req.body,
req.headers['stripe-signature'],
STRIPE_WEBHOOK_SECRET
);
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
if (session.metadata?.referralCode) {
await daisychain.submitReferral({
referrerIdentifier: session.metadata.referralCode,
customerId: session.customer,
orderId: session.id,
orderAmount: session.amount_total / 100,
metadata: {
platform: 'stripe',
subscription: session.subscription
}
});
}
}
res.sendStatus(200);
});
Frontend Frameworks
React Integration
// ReferralForm.tsx
import { useEffect } from 'react';
import { DaisyChain } from '@daisychain/sdk';
const client = new DaisyChain({
apiKey: process.env.NEXT_PUBLIC_DAISYCHAIN_API_KEY,
storeId: process.env.NEXT_PUBLIC_STORE_ID
});
export function ReferralForm() {
useEffect(() => {
// Automatically capture referrals from URL
client.captureFromURL();
// Add referral field to form
client.injectReferralField('#signup-form', {
label: 'Referral Code',
validateOnInput: true,
onValidation: (result) => {
console.log('Validation result:', result);
}
});
}, []);
return (
<form id="signup-form">
{/* Your form fields */}
</form>
);
}
Vue.js Integration
<!-- ReferralForm.vue -->
<template>
<form id="signup-form">
<!-- Your form fields -->
</form>
</template>
<script>
import { DaisyChain } from '@daisychain/sdk';
export default {
mounted() {
const client = new DaisyChain({
apiKey: process.env.VUE_APP_DAISYCHAIN_API_KEY,
storeId: process.env.VUE_APP_STORE_ID
});
client.captureFromURL();
client.injectReferralField('#signup-form');
}
}
</script>
Mobile Apps
React Native
// ReferralService.ts
import { DaisyChain } from '@daisychain/sdk';
class ReferralService {
private client: DaisyChain;
constructor() {
this.client = new DaisyChain({
apiKey: Config.DAISYCHAIN_API_KEY,
storeId: Config.STORE_ID
});
}
async trackPurchase(order) {
try {
await this.client.submitReferral({
referrerIdentifier: order.referralCode,
customerId: order.customerId,
orderId: order.id,
orderAmount: order.total,
metadata: {
platform: 'react-native',
appVersion: Config.VERSION
}
});
} catch (error) {
console.error('Failed to track referral:', error);
}
}
}
export default new ReferralService();
iOS (Swift)
// ReferralManager.swift
import Foundation
class ReferralManager {
static let shared = ReferralManager()
private let apiKey = "your_api_key"
private let storeId = "your_store_id"
private let baseUrl = "https://api.daisychain.la/api"
func trackPurchase(
referralCode: String,
customerId: String,
orderId: String,
amount: Double
) {
let url = URL(string: "\(baseUrl)/referrals")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue(apiKey, forHTTPHeaderField: "X-API-Key")
request.setValue(storeId, forHTTPHeaderField: "X-Store-ID")
let body: [String: Any] = [
"referrerIdentifier": referralCode,
"customerId": customerId,
"orderId": orderId,
"orderAmount": amount,
"metadata": [
"platform": "ios",
"appVersion": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
]
]
request.httpBody = try? JSONSerialization.data(withJSONObject: body)
URLSession.shared.dataTask(with: request) { data, response, error in
// Handle response
}.resume()
}
}
Need More Help?
- Check our API Reference
- See the Quick Start Guide
- Contact our support team