Accessing transaction data in a Shopify email notification

Recently I needed to add a line to the Shopify Order Confirmation email that included the last 4 digits of the credit card used. This was more difficult than it needed to be, so I’m writing this post in hopes it’ll rise to the top in Google and help others trying to do the same thing.


You need to access the transaction object through a collection of transactions, like so:

{% for transaction in transactions %}
{{ transaction.payment_details.credit_card_number }}
{% endfor %}

This was stupidly difficult to track down. First, I went to the email variables article that’s referenced when you’re editing a notification. There, it states:

Notifications have access to every transaction property. Please see our Transaction API documentation here for a full list of the properties.

So I checked out that article, which didn’t help at all. Dead end.

After a few more searches, I finally found this thread in the forums that addressed my problem exactly. Reading through some of the comments, I thought I had hit another dead end, until I read the last comment in the thread, which pointed me to the thread that answered my question. Thanks to Mikkel Jakobsen for tracking down the answer!

Podcasts in Google Music

UPDATE (2/3/2016) – In October of 2015, Google announced that they’d be adding Podcasts to Google Play Music. Great news! It looks as if they’re starting to slowly roll out this functionality–some users are reporting that they’re seeing the new Podcasts section in their app. I don’t see anything in my app yet, but when I do, I’ll be sure to write a review here.

UPDATE (4/15/2015)Pocket Casts is my new favorite podcast player for Android.

UPDATE (8/26/2014) – Google Music still hasn’t added podcast support, and at this point I doubt they ever will. I’ve started using Podcast Addict to listen to podcasts exclusively on my Nexus 5, so I don’t need to sync podcasts and their playback status with another device or library. It even has Chromecast support.

UPDATE (8/9/2013) – Now that Google Music has become a subscription service, I’ve moved over to it exclusively for my music. So far, I’ve been very happy with the service–especially the seamless integration with the Chromecast at home. However, they still haven’t added native podcast support.

You can get the Chromecast at Amazon for $35. I highly recommend it.

Chromecast at Amazon

UPDATE (9/4/2012) – Still no native podcast support in Google Music. This continues to be the best way for me to get podcasts into Google Music.

A few people have said that they don’t have the check box for including podcasts. To make sure this check box appears, you need to tell Google Music that you keep your music in iTunes (look for “Location of my music collection” on the Advanced tab). Once you’ve done that, you’ll see the option to upload podcasts.

ORIGINAL POST (1/4/2012):

I still think it’s only a matter of time before Google Music adds podcast subscriptions natively. But until that happens, I’ve found a solution to get podcasts into your Google Music account that uses iTunes as the podcast manager.

With Google Music, you can download the Music Manager, a small application that acts as the link between your computer and Google Music. With Music Manager, you can upload your current library (you specify the location) or download the music you’ve purchased through Google (someday I expect the ability to also download music you’ve uploaded). But iTunes podcasts aren’t included in that library upload by default.

Under the Advanced tab in Music Manager is a checkbox to ‘Include podcasts in uploads’. Check that box and now you’ve got your podcasts available in the cloud, accessible from the web and the Google Music app on your Android phone. If you leave both iTunes and Music Manager running in the background, new podcasts will be downloaded and uploaded without any supervision.

Also, make sure iTunes is selected as the location of your music collection:

google music podcasts

Here are a few of my favorite podcasts:

Using Markdown for Email Templates in Rails

I’ve been working on a Rails freelance project that has a lot of email templates. For the last year, I’ve had two versions of each template–an HTML template and a text template. For a welcome email, I had both welcome.html.erb and welcome.text.erb. The worst part about this setup is that when you need to make a change to the email, you need to change two files. This isn’t very DRY, so I finally went in search of a better way to do this.
I found several StackOverflow questions that helped me get to my current solution. If you’re interested in the context, here they are:

Markerb gem

Using Markdown seemed like a great solution, so I started digging into the Markerb gem. This gem, combined with a parser (I’m using the recommended Redcarpet), allows you to write just one email template–in my case, welcome.markerb. Using standard Markdown format, I now only have to manage a single template, which is then parsed into both the text part and HTML part when the email gets sent.

Once you add Markerb to your Gemfile and run the bundle command, all you need to change is the extension on your template file and then reformat your templates to use Markdown. Nothing changes in your ActionMailer. When Rails goes looking for the template, Markerb takes over, parses the file, and spits out the text and HTML parts that get sent out.

Tagging past Shopify customers in ConvertKit via API

We’ve recently started using ConvertKit for our email marketing for Stitch People, and I LOVE IT. It’s flexible, easy to create automation sequences (called courses), easy to move people in and out of courses based on any number of events (purchase, link click in an email, etc.), easy to tell exactly which form someone signed up on, and much more.
The first step in my migration to ConvertKit was to start collecting new subscribers and customers into ConvertKit, and to tag them automatically for easy segmentation later. This included writing a small Shopify app to automatically subscribe customers and tag them based on what they purchased. I’ll write another post about this later.

Once all new subscribers were being funneled into ConvertKit instead of Mailchimp, it was time to clean up old data. The first place I started was to tag past Shopify customers based on the product they purchased. We have a relatively small number of products right now (different variants of a book is our main product), but this would work just as well for a large catalog of products and customers.

To do this, I’ll be using the ConvertKit API (documentation found here).

Step 1: Create the tags in ConvertKit

The main API endpoint we’re going to be hitting is the Add Subscriber to Tag endpoint. And since the API doesn’t support creating new tags yet, you’ll need to create these tags through the website first. Head to the Subscribers area, and click ‘Create Tag’ at the bottom of the right sidebar. That’ll bring up the box to create a new tag.

convertkit tag creation

You can come up with your own naming convention for tags, but my general rule of thumb is to be descriptive. You may know what an obscure tag means when you create it right now, but your 6-months-from-now self won’t, and you’ll kick yourself when you have a bunch of people tagged, but you don’t know why.

For example, I use tags like ‘diy-physical-book’ and ‘diy-ebook’ to differentiate between two different variants of the DIY Stitch People book. I prefixed it with ‘diy’ because we’ll be releasing more books later, for which we will have physical and digital copies. For those, I’ll create tags like ‘farm-animals-physical-book’ and ‘zoo-animals-ebook’. These will be easy to decipher down the road.

Step 2: Grab your list of customers from Shopify

Next, head to Shopify and do an export of all your orders. Head to the Orders tab, and hit the Export button at the top. Make sure you select the All Orders radio button, and export the orders, not transaction histories. I use the CSV for Excel, Numbers, etc. option. I’ll eventually be uploading this to Google Drive.

shopify order export

Step 3: Make separate lists of email addresses for each tag

This will likely be the most time-intensive step in this whole process. Now you need to take the CSV from Shopify and filter through several times to generate lists of email address for each tag you want to apply. For me, I created three lists: one for physical book purchasers, one for ebook purchases, and one for physical + ebook purchases. These are the three tags I’m using, and now I need to come up with three separate lists of email addresses–one for each tag.

For this step, I used Google Spreadsheets. You could also use Excel, Numbers, or any other spreadsheet program that lets you quickly and easily filter your table based on column contents. Once you have your CSV file loaded in whatever application you’re using, you need to filter the table by products/variants. In Google Spreadsheets, you can use the Filter feature and then select the ‘lineitem_name’. In my case, I’ve been through several different iterations of the product and variation titles, so for my ebook DIY book buyers, I had to select several values:

filtering lineitem_name

Once filtered, copy those email address and throw them into a new tab in the spreadsheet. Make sure you label the tab so you know which list you have. Repeat this step for any other tags you want to apply.

Step 4: Write the script to tag the subscribers

Now comes the fun part. You can choose whatever language you want, as long as you have a way to make an HTTP POST request. I chose Ruby and used Faraday. Here’s a gist:

First thing you’ll want to do is populate the arrays of email addresses. Take the email address lists from your individual spreadsheet tabs and format them as strings in an array. I used a text editor (Atom) to quickly do this, then just pasted in the result. I was dealing with about 2,000 email addresses total.

Once you’ve created the arrays, head to your ConvertKit account page to find your API key. Put that value in.

Finally, you’ll need to grab your ConvertKit tag ids and populate those into the URL strings. Head to ConvertKit, click on the tag you want, and grab the ID from the URL:

tag url

Put that value in for the XXXX between ‘tags’ and ‘subscribe’ for each tag.

Step 5: Run the script

Now it’s time for the magic. Save the file you’ve been editing and then run it. For Ruby, I just opened a terminal window, navigated to the folder where the file was, and typed ‘ruby filename.rb’ to run it. Mine took about 10 minutes to run to completion. Once that was done, all my subscribers were properly tagged with the product they had purchased, allowing me to create Courses and Segments based on those tagged subscribers.

Showing multiple currencies in Shopify

We’ve been getting a lot of emails lately from people asking what the DIY Stitch People book costs in their currency (GBP, AUD, etc). We normally just head to Google, grab the latest exchange, and reply to the email with the result. Today I decided to fix that process.
After some searching, I found the article I needed: Showing multiple currencies in a drop-down list on your storefront

It’s pretty straightforward if you know what you’re doing with Shopify theme files. If you follow the instructions in that article, you’ll end up with a currency dropdown in your header. I didn’t love the placement, so I took it a step further and put the currency dropdown right next to the display price:

Screen Shot 2015-02-10 at 7.41.50 PM

To get this, you just need to tweak where you’re including the snippet. To get it in the header, the article asks you to put it in theme.liquid. I instead put it on the product page, product.liquid, below the price (and outside of the span that contains the price):

<span class="current_price">
 {{ product.price | money }}

// Add this code
{% if settings.show_multiple_currencies %}
  <span class="currency_switcher">
    {% include 'currencies-switcher' %}
{% endif %}

Then I just added some CSS (style.css.liquid) to get the dropdown sitting next to the price (but not too close):

.currency_switcher {

The result gave me that currency dropdown box right next to price, which I think is much more visible than having it buried in the header.