To get you started with Supermatic, we're going to do a fun experiment. We will set up an automation that will send an email to you when Scrooge McDuck shops in your store. Maybe not the most useful automation, but it will at least cover many of Supermatic's features.

In this tutorial, we assume that you have already installed Supermatic for your Shopify store and that you are signed in to the Supermatic dashboard.

Let's get started!

Setting up an email template

To be able to send out emails with Supermatic, we first have to set up an email template. Email templates are basically just HTML files that control the content of your emails. They are also dynamic, so you can personalize them with the recipients name and other changing content.

Go to email templates in the dashboard, and click "New email template".

First you have to choose a unique name for your template. We suggest the name "Scrooge McDuck warning".

Next, you fill in the content of your template. Here's a minimal example:

Similarly to Shopify templates, which uses Liquid for dynamic content, you can make Supermatic email templates dynamic as well. But instead of Liquid, we use JavaScript through a templating language called EJS.

With the power of JavaScript you can make the template a little bit more interesting:

With the added conditional, we will see if Scrooge is a big spender or a cheapskate. Hit "Create email template" and you're done with your template.

Writing the code

Next up is setting up our automation. Go to the automation list and click "New automation".

Just as with the email template, you have to give the automation a unique name. Let's go with "Scrooge McDuck warning" here as well.

Now it's time to start coding. Supermatic automations are written in JavaScript. To see a very quick and minimal example, put this in the code editor.

Click "Create automation" and immediately after that click "Test". At the bottom of the page, you should now see a log with the message "Hello, World!".

But of course, for your automation you want to do something a bit more interesting:

Let's break this down a bit. At the top of the file, we import the email library from Supermatic's SDK. The email library lets you send out emails from your automations.

Next, we export an event handler called handleEvent. This function is called with the available event data. If your automation doesn't need that data, wrapping your code in the event handler isn't necessary.

Inside the event handler, we use something called shopifyPayload on the event's payload. This is the event data exactly as it looked when we received it from Shopify. Here, we use it to determine if the customer's name really is "Scrooge McDuck".

And finally, we use email.send to send the email. As you can see, we provide the price that we use in the email template, in the template data.

Note that you have to replace [ENTER YOUR EMAIL ADDRESS] with your own email address.

Now you can confirm your code changes by clicking "Update".

Setting up a trigger

Finally, we also have to tell Supermatic when to run the automation. This is done by setting up a trigger for a specific Shopify event.

The earliest point we can know the name of the customer, is when they have filled in their name in the checkout, and clicked "Continue to shipping". Then, Shopify will send a "Checkout update" event. Go ahead and add a trigger with that event name and a zero second delay.

Save your new trigger by clicking "Update".


Now we can try out our automation. Go to your store, add something to cart, and continue to checkout. At checkout, make sure to fill in "Scrooge" as first name and "McDuck" as last name. Fill in any address below and click "Continue to shipping". Within in a minute or so, you will receive an email telling you if Scrooge is a big spender or a cheapskate.

We hope you enjoyed this tutorial and that you are now ready to do something a bit more interesting with Supermatic!

If you have any questions or need any help with your automations, drop us an email at support@supermatic.app.