Setting up Yotpo Mail After Purchase

From Spiffy Stores Knowledge Base

If you've already added the Yotpo Reviews Widget, you now have the option of adding the Mail After Purchase function. This process takes a few steps, but the benefit from this is that you can email customers automatically after they make a purchase, rather than emailing your customers manually or using a service like MailChimp to email your customers.

Most stores currently have no way of collecting reviews automatically. Yotpo's free service allows you to automatically email your customer after they've made a purchase prompting them to review your store or the product. The reviews can then either display in your store automatically, or you can use Yotpo's built-in moderation to approve reviews before they are displayed.

The setup cost of the Yotpo Mail After Purchase function is a one-off fee of $35 AUD. To have us set it up for you, please email us with the following information...

  1. The email address and password you use to log in to Yotpo. They need to be for the administrator of the Yotpo account, as we cannot generate keys without admin access.

  2. Your Yotpo App Key and Secret Key

  3. Your store's name

Retrieving your Yotpo App Key and Secret Key

App Key

  1. Log in to your Yotpo Dashboard
  2. Hover over the person icon in the top right, and click "Settings".
  3. Scroll down to the bottom of the page and copy your APP Key
  4. Paste your App Key into the email you send us.

Secret Key

  1. To retrieve your secret key, you'll need to click the "Get Secret Key" button.
  2. A link will be sent to you by email with a code.
  3. Paste the code from the email into the "Enter the code" box.
  4. Your Secret key will now be displayed.
  5. Paste your Secret Key into the email you send us.

When you have all the info we need, please email us with this info, and request that we add the conversion code to your store for you.

Want to do it yourself?

To send order data to Yotpo, you'll need to generate a user token (UTOKEN). Yotpo documentation on how to do this can be found at https://core-api.yotpo.com/v1.0/reference#about-authentication

A handy utility to do this is the Postman App.

Once you have your user token, copy the code snippet below, and paste it into the "Additional Content & Scripts" field in the Preferences -> Checkout & Payment section of your store's admin. You'll need to update the <APPKEY> and <UTOKEN> in the code with your Yotpo App Key and your Yotpo User Token.

One note about this DIY solution though... the UTOKEN lasts only 14 days, so you would need to update it every 14 days to keep it running.

<!-- Yotpo mail after purchase -->

<script>

$(document).ready(function(){
  var data = JSON.stringify({
	"platform": "general",
	"utoken": "<UTOKEN>",
	"email": "{{ customer.email }}",
	"customer_name": "{{ customer.first_name }}",
	"order_id": "{{ order_name }}",
	"order_date": "{{ order_date | date: "%Y-%m-%d" }}",
	"currency_iso": "{{ shop.currency }}",
	"products": {% for item in line_items %}{
		"{{ item.sku }}": {
			"url": "{{ item.product.url }}",
			"name": "{{ item.title }}",
			"image": "{{ item | img_url: '2048x2048' }}",
			"price": "{{ item.price | money_without_currency }}"
		}{% unless forloop.last %},{% endunless %}{% endfor %}
	}
  });

  var xhr = new XMLHttpRequest();
  var url = "https://api.yotpo.com/apps/<APPKEY>/purchases/";
  xhr.open("POST", url, true);
  xhr.setRequestHeader("Content-Type", "application/json");
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
        var json = JSON.parse(xhr.responseText);
        console.log(json);
    }
  };
  xhr.send(data);

});

</script>

<!-- End Yotpo mail after purchase -->