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"
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.
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).
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.
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:
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.
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:
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.