Loyalty: Using Zapier for your punch card program

What is Zapier?

Zapier is an online tool that helps you automate workflows by connecting apps and services that you use. You can automate tasks without having to build an integration yourself or hiring someone to build an integration for you.

Combining Zapier with Campaign Monitor allows you to pass data about your subscribers from one platform to another!

Building Zaps in order to pass the correct data into Campaign Monitor requires coding knowledge of Javascript. If you’re unfamiliar with Javascript, please ask a developer for help.

What types of Zaps should you build?

The types of Zaps you’ll want to build is dependent on the actions that will increase a subscriber’s Punch Card Stamps amount.

For a transaction-based punch card program, any time a valid transaction is made, you will want to adjust a subscriber’s Punch Card Stamps based on the number of products or services that were purchased in the last transaction. Example Zaps include:

  • Increasing Punch Card Stamps in Campaign Monitor when an order is created/paid or an appointment is made
  • Decreasing Punch Card Stamps in Campaign Monitor when an order is canceled or an appointment is canceled

For an engagement-based punch card program, you will want to adjust a subscriber’s Punch Card Stamps if you’ve completed some action on your website like filling out a survey, creating an account, or leaving a comment or review. Example Zaps include:

  • Increasing Punch Card Stamps in Campaign Monitor when an account is created
  • Increasing Punch Card Stamps in Campaign Monitor when a comment or review is created.

Your Zap triggers will be dependent on the integration that Zapier supports.

Building your Punch Card Program with Campaign Monitor and Zapier

Step 1. Set up your punch card data in Campaign Monitor

If you’re just starting your punch card program, you’ll need to make sure your list has the following recommended custom fields. These fields will allow you to run a loyalty program smoothly in Campaign Monitor.

We recommend creating a new list that stores all of your loyalty program subscribers. Once you’ve created your list, add the following custom fields.

Custom Field NameData TypePersonalization TagDescription
Punch Card StampsNumber[PunchCardStamps]Count of how many stamps a subscriber has accrued.
Completed Punch CardsNumber[CompletedPunchCards]Count of how many punch cards a subscriber has completed.
Last Order CountNumber[LastOrderCount]Count of how many items were purchased in the last order.
Increase Punch Card StampsText[IncreasePunchCardStamps]A custom field that is set to “true” or “false” used to enter a subscriber into a segment - pulling them into a journey that will adjust the punch card stamps.
Decrease Punch Card StampsText[DecreasePunchCardStamps]A custom field that is set to “true” or “false” used to enter a subscriber into a segment - pulling them into a journey that will adjust the punch card stamps.

Adding these fields can be done within the Campaign Monitor UI or you are free to use the Lists API to add these fields.

Step 2. Connect the Campaign Monitor app in Zapier

You’ll want to connect your Campaign Monitor app to Zapier as your first step.

  1. In Zapier, navigate to the apps section.
  2. Add the Campaign Monitor app.
  3. Apply your Campaign Monitor API key and click the continue button.
    Note: Follow these instructions to find your API key in Campaign Monitor.

Be sure to connect apps that will trigger loyalty-specific events as well.

Step 3. Create your Zaps in Zapier

For these Zaps, the following steps are typically required:

  1. A trigger from your eCommerce store or website.
  2. (If data is coming from an eCommerce / POS app) A “Code by Zapier” action to convert Line Item Quantities to a single Order Count value.
    Note: Most eCommerce / POS integrations store the total number of items ordered as individual quantities of a single line item and must be summed before being passed into Campaign Monitor.
  3. A “API Request in Campaign Monitor” action to send data over to Campaign Monitor.

As noted earlier, your Zaps are dependent on the type of app you’re integrating with and the trigger you’d like to use. We’ll be using the Shopify integration to pull our order data that will increase our subscriber’s Punch Card Stamps, but feel free to adjust the steps as necessary!

Create a Zap to increase a subscriber’s Punch Card Stamps

  1. Create a new Zap in Zapier and name it appropriately.
  2. Set up your eCommerce / POS trigger.
    1. In the trigger step, select “Shopify” as your app.
    2. In the “event” section, select “New Paid Order” and click “Continue”.
    3. Select your Shopify account and click “Continue”
    4. Test your trigger by selecting a record of your choice.
  3. Add a “Code by Zapier” action to convert Line Item Quantities to a single Order Count value.
    1. Select the “Run Javascript” option under “Event” and click “Continue”.
    2. Under the Input Data section:
      1. Add the string lineItemQuanitity in the first box.
      2. In the second box, insert data from your app that stores the number of line items ordered.
        Note: In Shopify, this is called “Line Items Quantity”.
    3. In the code section, add the following Javascript code.
      Note: You can update this code to Python if you so prefer.
      
                          // Initialize variables
                          var lineItemQuantity = inputData.lineItemQuantity; // Initialize input data
                          var orderCount = 0; // Initialize orderCount value
                          
                           // Convert Shopify Line Items from string to an integer
                          var lineItemQuantityArray = lineItemQuantity.split(',').map(Number);
                          
                          // Sum Shopify Line Items
                          lineItemQuantityArray.forEach( num => { orderCount += num; })
                          
                          // Return sum of line items ordered as orderCount
                          output = [{orderCount}];
                      
    4. Click “Continue” and test your code.
  4. Add a new action to send data over to Campaign Monitor.
    1. In the action step, select the Campaign Monitor app.
    2. In the “event” section, select “API Request (Beta)” and click “Continue”.
    3. Select your Campaign Monitor account and click “Continue”.
    4. Under “HTTP Method”, select “PUT”.
    5. Under “URL”, use the following URL: https://api.createsend.com/api/v3.3/subscribers/{listid}.json
      Note: Replace {listid} with your loyalty lists’ ID. To find your list’s ID, navigate to your list in Campaign Monitor, and select the “Settings” option. Scroll to the bottom of the page to find your list ID.
    6. Under “Query String Parameters”, type in “email” in the first box. In the second box, select the app’s parameter that stores your customer’s email address. This will typically be called “Email”.
    7. In the body, add the following JSON code:
      
                          {"CustomFields": [
                              {"Key":"LastOrderCount", "Value":"{LastOrderCount}"},
                              {"Key":"IncreasePunchCardStamps", "Value":"true"}],
                          "ConsentToTrack": "Unchanged"}
                      
    8. Replace the {LastOrderCount} text with the Order Count output from the “Code by Zapier” step.
      1. To do so, highlight the {LastOrderCount} text and search for the “2. Run Javascript in Code…” option under the “Insert Data…” dropdown.
      2. Select “Order Count” from the list.
      3. After selecting the “Order Count”, your highlighted text will be replaced with the appropriate object.
    9. Click “Continue” and test your step.
  5. Publish your Zap.

Create a Zap to tell Campaign Monitor when punch card amounts need to be decreased

If you’ve already created a Zap to increase a subscriber’s Punch Card Stamps, you can quickly create this Zap by duplicating your previous Zap. After your Zap has been duplicated, follow steps 2 and 4 to make the necessary changes. Otherwise follow the steps below.

  1. Create a new Zap in Zapier and name it appropriately.
  2. Set up your eCommerce / POS trigger.
    1. In the trigger step, select “Shopify” as your app.
    2. In the “event” section, select “Updated Order” and click “Continue”.
    3. Select your Shopify account and click “Continue”
    4. In the Trigger section, update the “Payment”, “Order”, and “Fulfillment Status” fields to the appropriate status when an order is canceled.
    5. Test your trigger by selecting a record of your choice.
  3. Add a “Code by Zapier” action to convert Line Item Quantities to a single Order Count value.
    1. Select the “Run Javascript” option under “Event” and click “Continue”.
    2. Under the Input Data section:
      1. Add the string lineItemQuanitity in the first box.
      2. In the second box, insert data from your app that stores the number of line items ordered.
        Note: In Shopify, this is called “Line Items Quantity”.
    3. In the code section, add the following Javascript code.
      Note: You can updated this code to Python if you so prefer.
      
                          // Initialize variables
                          var lineItemQuantity = inputData.lineItemQuantity; // Initialize input data
                          var orderCount = 0; // Initialize orderCount value
      
                          // Convert Shopify Line Items from string to an integer
                          var lineItemQuantityArray = lineItemQuantity.split(',').map(Number);
      
                          // Sum Shopify Line Items
                          lineItemQuantityArray.forEach( num => { orderCount += num; })
      
                          // Return sum of line items ordered as orderCount
                          output = [{orderCount}];
                      
    4. Click “Continue” and test your code.
  4. Add a new action to send data over to Campaign Monitor.
    1. In the action step, select the Campaign Monitor app.
    2. In the “event” section, select “API Request (Beta)” and click “Continue”.
    3. Select your Campaign Monitor account and click “Continue”.
    4. Under “HTTP Method”, select “PUT”.
    5. Under “URL”, use the following URL: https://api.createsend.com/api/v3.3/subscribers/{listid}.json
      Note: Replace {listid} with your loyalty lists’ ID. To find your list’s ID, navigate to your list in Campaign Monitor, and select the “Settings” option. Scroll to the bottom of the page to find your list ID.
    6. Under “Query String Parameters”, type in “email” in the first box. In the second box, select the app’s parameter that stores your customer’s email address. This will typically be called “Email”.
    7. In the body, add the following JSON code:
      
                          {"CustomFields": [
                              {"Key":"LastOrderCount", "Value":"{LastOrderCount}"},
                              {"Key":"DecreasePunchCardStamps", "Value":"true"}],
                          "ConsentToTrack": "Unchanged"}
                      
    8. Replace the {LastOrderCount} text with the Order Count output from the “Code by Zapier” step.
      1. To do so, highlight the {LastOrderCount} text and search for the “2. Run Javascript in Code…” option under the “Insert Data…” dropdown.
      2. Select “Order Count” from the list.
      3. After selecting the “Order Count”, your highlighted text will be replaced with the appropriate object.
    9. Click “Continue” and test your step.
  5. Publish your Zap.

This code is provided as is, without warranty, but we’ll do our best to answer questions you have about it here.

Supporting custom code is outside of the scope of Campaign Monitor by Marigold Support, so if you need help with this, or other code you’re working on, the best place to ask is on Stack Overflow. You’re still welcome to ask Support just in case it’s something unrelated to the code that isn’t working, but you may be directed to an outside source to get help from the community.

Step 4. Create your segments in Campaign Monitor

In order to trigger Punch Card Program-specific journeys in Campaign Monitor, you’ll need to create segments in your loyalty list. Navigate to your loyalty list in Campaign Monitor and create the following segments:

A segment that subscribers join when their punch card stamps need to be increased

This segment will be used to enter subscribers into a journey that increases their Punch Card Stamps. Create a rule where the “Increase Punch Card Stamps” custom field matches exactly the word “true”.

Name this segment “Increase Punch Card Stamps”.

A segment that subscribers join when their punch card stamps need to be decreased

This segment will be used to enter subscribers into a journey that decreases their Punch Card Stamps. Create a rule where the “Decrease Punch Card Stamps” custom field matches exactly the word “true”.

Name this segment “Decrease Punch Card Stamps”.

Step 5. Adjust your existing campaign designs or create new ones that surface punch card data

Keeping your customer informed on how many stamps they have on their punch card and how many more stamps they need until their next reward can drive your customers to purchase more from you. A message that says “you need to buy 3 more coffees for your next reward” incentivizes the customer, driving them towards a finish line!

For instructions on how to surface loyalty information in your emails, view this article.

Step 6. Create your Punch Card automations

Automations are necessary to run your loyalty program smoothly and efficiently. Here is a list of example journeys you can build, including directions on how to set them up in Campaign Monitor:

Redemption journeys

At this time, in relation to punch card programs, Campaign Monitor supports automatically providing a customer a coupon code when they complete a punch card. The customer will ideally receive another coupon when they’ve completed another card.