Shopify

A leading cloud-based, multichannel commerce platform designed for small and medium-sized businesses.

To integrate your Shopify store, you can use the official built-in plugin but first you need to create a private app in your Shopify store.



1. Login to your Shopify admin panel and navigate to Apps> Manage private apps (a link at the bottom)

Shopify private apps

2. Create a new private app

Shopify private apps

3. Name the app as you like and add your email address to be notified in case of problems. Then you need to scroll down a little bit to the permissions section. Make sure your private app will contain all of these permissions with read/write access:

Customers (READ access) > Access scopes: read_customers, write_customers
Orders (READ access) > Access scopes: read_orders, write_orders
Script tags (READ and WRITE access) > Access scopes: read_script_tags, write_script_tags

Shopify app details

Do not change anything else and save the app.

4. Once the app is created you'd need the API key, Password and your store's URL address

Shopify private app

5. Now you need to navigate to your Post Affiliate Pro merchant panel and to Configuration->Plugins section

PAP configuration

6. You need to find the Shopify API and notification handling plugin and activate it.

PAP configuration

7. Once activated you need to click on Configure next to it and enter your store URL, api key and password and configure how you want the integration to behave.

PAP configuration

8. Save the configuration and if no error pops up you are done and your site should start tracking.













If, for some reason, you cannot use the plugin and you want to integrate your Shopify site manually, you can use the following steps.

1.

Login and navigation

Login to your admin panel. Navigate to Settings> Checkout and scroll down to Additional Content & Scripts in the section Order processing.

2.

Code

The sale tracking code to track one commission per order is this:

<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
	if (window.location.href.indexOf('/thank_you') > 0) {
		PostAffTracker.setAccountId('Account_ID');
		var sale = PostAffTracker.createSale();
		sale.setTotalCost('{{subtotal_price | money_without_currency | replace: ',', '' }}');
		sale.setOrderID('{{order_number}}');
		sale.setProductID('{{product_ids}}');

		PostAffTracker.register();
	}
</script>

And now just save it and you are ready to track the sales now.

If you would want to use also Lifetime Commissions plugin you need to add the following line to right under sale.setProductID('{{product_ids}}'); to add the customer's email address to the order:
sale.setData1(Shopify.checkout.email);

Or you can use customer ID instead of email, to keep it private:

sale.setData1(Shopify.checkout.customer_id);

3.

Per product integration

In case you want to track per product commissions, you should use this integration code instead of the one from step 2.

<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
if (window.location.href.indexOf('/thank_you') > 0) {
    PostAffTracker.setAccountId('Account_ID');
    var discountpercent = 1;
    var discountcoupon = '';
    if (Shopify.checkout.discount != null && typeof Shopify.checkout.discount.amount != 'undefined') {
        var total = Number(Shopify.checkout.discount.amount.replace(',', '')) + Number(Shopify.checkout.subtotal_price.replace(',', ''));
        discountcoupon = Shopify.checkout.discount.code;
        discountpercent = 1 - (Shopify.checkout.discount.amount.replace(',', '') / total);
    }
    var giftcard = 0;
    if ((typeof Shopify.checkout.gift_cards != 'undefined') && (Shopify.checkout.gift_cards.length > 0) && (Shopify.checkout.gift_cards != null) && (Shopify.checkout.gift_cards != '') && (Shopify.checkout.gift_cards[0].amount_used > 0)) {
        giftcard = Shopify.checkout.gift_cards[0].amount_used;
    }

    var item = 0;
    while (typeof Shopify.checkout.line_items[item] != 'undefined') {
        var subtotal = Shopify.checkout.line_items[item].line_price.replace(',', '') * discountpercent;
        if (giftcard > 0) {
            var rest = giftcard - subtotal;
            subtotal = subtotal - giftcard;
            giftcard = rest;
        }
        if (giftcard < 0) {
            giftcard = 0;
        }
        if (subtotal < 0) {
            subtotal = 0;
        }
        var sale = PostAffTracker.createSale();
        sale.setTotalCost(subtotal);
        sale.setOrderID(Shopify.checkout.order_id + '(' + (item + 1) + ')');
        sale.setCurrency(Shopify.checkout.currency);
        var papProductId = Shopify.checkout.line_items[item].sku;
        if (papProductId == '') {
            papProductId = Shopify.checkout.line_items[item].product_id;
        }
        sale.setProductID(papProductId);
        if (Shopify.checkout.line_items.length != (item + 1)) {
            if (typeof sale.doNotDeleteCookies === 'function') {
                sale.doNotDeleteCookies();
            }
            PostAffTracker.register();
        } else {
            if (typeof PostAffTracker.registerOnAllFinished === 'function') {
                PostAffTracker.registerOnAllFinished();
            } else {
                PostAffTracker.register();
            }
        }
        item++;
    }
}
</script>

You are done, this is all needed. Save your changes and you are ready to use the integration.

If you would want to use also Lifetime Commissions plugin you need to add the following line to right under sale.setCurrency(Shopify.checkout.currency); to add the customer's email address to the order.

sale.setData1(Shopify.checkout.email);


Additional info can be found here:

https://docs.shopify.com/themes/liquid/objects/order

Do not forget to integrate your shop with the click tracking code.

You can insert it into the theme of your store this way: 

Online store> Themes> Customize theme (top right corner)> Theme option (top left corner)> Edit HTML/CSS

In 'Layout' directory, there is a file called 'theme/liquid'. Insert the click tracking code right above </BODY> tag in that file and save it.