Step One: Integrate Click Tracking
Add the one-line script below to your main site template just before the closing </body>
tag. This script must be on every page, as it takes the tracking URL and turns it into a first-party cookie.
<script defer src="https://static.shopmy.us/Affiliates/sms_aff_clicktrack.js"></script>
Step Two: Integrate Order Tracking
Add the following script to your order confirmation page. Replace placeholders (marked with ***
) with actual checkout system values.
<script>
const cookies = document.cookie.split(';').reduce((res, cookie) => ({ ...res, [(cookie.split('=')[0] || '').trim()]: (cookie.split('=')[1] || '').trim()}), {});
const { sms_click_id, sms_click_time } = cookies;
const code = `***THE CODE USED AT CHECKOUT***`;
fetch(`https://api.shopmy.us/api/order_confirmation`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
orderAmount: `***THE ORDER TOTAL***`,
orderId: `***THE ORDER ID***`,
clickId: sms_click_id,
currency: `***THE ISO 4217 CURRENCY CODE, EX: USD***`,
is_returning_customer: false,
page_url: window.location.href,
code
})
})
.then(r => {
if (!r.ok) throw new Error('Invalid order request sent');
r.json();
})
.then(() => {
const now = new Date();
document.cookie = `sms_click_id=;expires=${now.toUTCString()};path=/;`;
document.cookie = `sms_click_time=;expires=${now.toUTCString()};path=/;`;
})
.catch(() => {
// ignore the error
});
</script>
Step Three: Handle Order Cancellations
Configure a POST request to be sent to the following endpoint whenever an order is cancelled. This is crucial for maintaining accurate tracking and reporting in our system.
This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security.
fetch(`https://api.shopmy.us/api/Affiliates/cancel`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
},
body: JSON.stringify({
order_id: '123456',
})
})
Step Four: Handle Order Updates
Configure a POST request to be sent to the following endpoint whenever an order is updated. We define an order update as whenever a order has new total amount, or currency change. This is crucial for maintaining accurate tracking and reporting in our system.
This endpoint uses your unique Brand Developer Key for authorization. Always keep your key confidential to ensure security
fetch(`https://api.shopmy.us/api/Affiliates/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer <YOUR_DEVELOPER_KEY>`,
},
body: JSON.stringify({
order_id: '123456',
currency: 'USD',
new_order_amount: '1234.56'
})
})
Step Five: Request Testing
Contact your Brand Success Manager to place a test order and test the integration end-to-end. We will communicate with you any test order IDs we place so they can be cancelled after the integration is verified.
By adding our integration code to your site, you are agreeing to the terms of the ShopMy affiliate network. Please review these terms here.