Select Page

You can have Zapier keep track of a number over time and post updates to Slack. This is useful for celebrating course sales or automatic weekly metrics reporting.

For this example, we’d like to post to Slack every time someone buys our Thinkific course. The Slack message will include the number of sales we’ve had in the month so far. We’ll assume you already have Slack and Thinkific connected to Zapier. If not, add the needed accounts before we get started.

You can add the counting and Slack steps anywhere in your Zap that gets triggered by a sale.

Start a new Zap and trigger it with Thinkific “New Full Enrollment” and choose your course. Click “Continue” then pull in samples and test the step. If no one has bought your course yet, go through a test enrollment, then return here in Zapier.

Add an action step to the Zap and search for “Code”. Choose “Run Python” and continue. Ignore “Input Data” and paste the following in the “Code” area:

store = StoreClient('4KD9QhA5lO')
count = store.get('students') or 12
count += 1
store.set('students', count)

return {'students count': count}

The important parts are “4KD9QhA5lO” and the number 12. Nothing else needs to be changed.

4KD9QhA5lO is a unique variable that sits on Zapier’s servers. If someone else uses Zapier’s Code feature and happens to also select 4KD9QhA5lO as their variable, you’ll have a problem; their code will update your variable and your code will update their variable. This is why we use a random string of numbers and letters so no one else happens to choose the same.

Feel free to just mash your keyboard, or generate a string of characters at this password generating site and uncheck “Include Symbols”, make it a reasonable length like 10 characters, then click Generate Password. The key point is to not be an obvious variable like “sales” or “courses” to ensure no one else on Zapier uses that same variable name. “4KD9QhA5lO” looks great.

The number 12 is your current number of sales this month. This number initializes the variable if it doesn’t exist already. If “or 12” isn’t in your code, it would start the variable at 0 and add one in the next line “count += 1”.

The variables “students” and “count” aren’t important here; they’re only used internally in this private code.

Click Continue. It should run the code and show “students count: 13” along with some other unimportant stats. The code has added 1 to your monthly count just like someone bought your course!

Next, add an action for Slack to Send a Channel Message, then choose your connected Slack account. Choose your channel or select “Use Custom Value (advanced)” if it’s a private channel.

To get that custom value for the private channel, go to that channel in Slack and click the three dots (More Actions) next to any message. Click “Copy Link” and paste it somewhere. The custom value is after “/archive/” in the URL and will look something like “G7H5ZD38F”. Paste that into the Custom Value for Channel ID in Zapier.

Make your Message Text celebratory, like:

"Welcome new [course name] student, [first name] [last name]! 
This makes [students count] students who joined this month!" 

Choose the placeholders in square brackets by clicking the + sign (Input Field) on the right and choosing from each appropriate step in your Zap. The rest of the step’s settings are optional.

Click Continue and send a test message to Slack to make sure all is working. You can delete this test message from Slack if you’d like.

A Key Step

You may have noticed an issue above! We updated the monthly count while testing the code step. But 13 isn’t the number of actual sales we’ve had this month. As it stands, the next time an actual sale comes through, it will count 14 sales in Slack. No bueno!

To fix this, change your unique variable slightly. I’ll change “4KD9QhA5lO” to “5KD9QhA5lO” for example. Since it’s a new variable, the “or 12” in the code will start the counting from 12, and add 1 to it in the next line. Then, when an actual sales comes through, the Slack step will post with the correct number of 13, as expected.

We had to do it this way to create the Slack step, otherwise Zapier wouldn’t let us turn on the Zap. Activate the Zap once all looks good.

Resetting Monthly

If you’d like to reset the counter each month, create a separate Zap that starts with the trigger “Schedule”. Choose “Every Month” and continue. Select the day of the month (probably 1) and time of day (probably Midnight).

Add a Code step and choose Run Python again. This time, paste the following in the Code area:

store = StoreClient('5KD9QhA5lO')
count = 0
store.set('students', count)
return {'students count': count}

Ensure you paste your variable of random characters correctly in this code. Note that I used the updated variable that starts with 5. It has to match the variable in your other Zap. “count = 0” resets the variable to 0 at the start of the month, ready for your first sale!

Please don’t use 5KD9QhA5lO or 4KD9QhA5lO for your variables since it may be likely other would try the same. Note that you can perform any actions you’d like in Zaps with this variable, but so can anyone else, so please keep it private!

For more reading, here’s the StoreClient documentation from Zapier.

If you’d like to see what we’re counting, head to our marketplace of free and paid products 😉