How to integrate with Cratejoy


To integrate Affiliatly with Cratejoy, you need to add two different codes: one for tracking referred visitors and for tracking purchases made by those referred visitors.


Getting ready


Before setting up the integration we strongly recommend to make a copy of the current theme to follow the rest of the process on the copy version.

This can be done on the design tab, then for the published design (theme) click on "Copy"

making a copy of the live design of the cratejoy store


Just in case you decide to ignore this step, Cratejoy will confirm our advice, warn you about the dangers of editing directly the live them and invite you to create a copy.

cratejoy warns to not modify the live version of the design


Now that we have a safe place to take care of this process, you can click on "Code" in the copy version of your design (theme).

open the cratejoy design to edit the code


Adding the visitors tracking code


This is the code you'll use to track visitors:

<script src="https://static.affiliatly.com/v3/affiliatly.js?affiliatly_code=AF-10XXX"></script>

Note: in the integration code, when you see β€œAF-10XXX”, you need to replace it with your own Affiliate ID as that is just an example.

Within the design (theme) files, you'll need to navigate to /html/base.html

Here you can paste the visitors tracking code below {{ js.base() }} like you'll see on the following illustration.

Then click on Save.

pasting the visitors tracking code


Adding the purchases tracking code


This is the code you'll use to track purchases:

<!-- affiliatly code start -->
	<script>
		{% set order_coupons = [] %}
		{% for c in order.coupons %}
		    {% do order_coupons.append(c.code_used) %}
		{% endfor %}

		var is_renew = '{{order.is_renewal}}';
		if( is_renew == 'False' )
		{
		var head = document.getElementsByTagName('head')[0];
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'https://static.affiliatly.com/v3/affiliatly.js?affiliatly_code=AF-10XXX&conversion=1&id_order={{order.id}}&order_price={{order.total_price}}&order_coupons={{ order_coupons | join(',') }}';

		head.appendChild(script);
		}
	</script>
<!-- affiliatly code end -->

Note: in the integration code, when you see β€œAF-10XXX”, you need to replace it with your own Affiliate ID as that is just an example.

For this one, let's go to /components/customer/thank_you/component.html

The place to paste this code is right below this part:

         {{ customer_helper.order_page("Thank you!") }}
    </div>

Please see the reference:

pasting the purchases tracking code

After clicking on Save, please click on the Design menu to get back to the themes selection screen


Publishing and testing


Now that we integrated the two codes we need to make this design(theme) the one that is applied on the store. For that, simply click on Publish.

publish the modified cratejoy design

After doing it, we'll be ready for testing:

To test your integration, open your site with β€œ?aff=1” parameter at the end of the address and make a test purchase.

After you have placed your order, you should see it in appear in your Affiliatly’s dashboard in the next minutes.

If everything was done right, you should see the visit and the purchase on your Affiliatly dashboard after a few minutes:

tracked purchase shown on dashboard


tracked purchase shown in referred order details

You're all set!

This is the end for this Cratejoy integration guide. If you have any more questions and the answers are not available here, please contact us and we will gladly assist you.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us