Track Shopify Revenue Live

Track Shopify Revenue Live

Table of Contents:

  1. Introduction
  2. Setting Up the Web Hook Trigger
  3. Creating a Node.js Step to Respond
  4. Introducing the Data Store Feature
  5. Retrieving and Updating Data with the Data Store
  6. Creating a Separate Workflow for Real-Time Updates
  7. Setting Up a Shopify Partner Integration
  8. Listening to Transactions on Shopify Apps
  9. Polling Source for Shopify Transactions
  10. Updating the Counter with New Transactions
  11. Finalizing the Workflow

Introduction

Welcome to another episode of the Pipe Dream speedrun! This week, we're diving into the world of IoT with our very first IoT episode. Our focus will be on using a counter that flips numbers based on a web hook, which is perfect for the Pipe Dream platform. This edition of Pipe Dream will specifically cover the Shopify counter. We'll learn how to track live transactions from a Shopify app and introduce a new feature called a data store that can be used in workflows.

Setting Up the Web Hook Trigger

To begin, let's create a brand new workflow on Pipedream. We'll start by setting up a web hook trigger that our counter can communicate with. After clicking "continue," we'll be provided with a unique URL that we can copy. Moving to the Smurl dashboard, we'll enter this URL in the counter's settings. This step ensures that the counter knows to retrieve a JSON object with an attribute called "number" from the Pipe Dream workflow.

Creating a Node.js Step to Respond

With Smurl now communicating with our workflow, we can create a new Node.js step. This step will return an HTTP response containing the JSON that Smurl can understand. In this step, we'll make a call to the "respond" helper and set the body to contain the attribute "number." For now, let's set the number to zero and ensure a status of 200. After testing and deploying this step, we should see the counter starting to work as it updates to zero.

Introducing the Data Store Feature

Manually updating the counter is neither fun nor efficient. Let's change that by bringing in a new feature called the data store. As mentioned earlier, the data store is a simple key-value storage utility that allows us to retrieve data within our web hook. We'll create a data store called "data" and specify that its attribute type is a data store. To retrieve the number from the data store, we'll use the "data.get" method and set it to "number." If the number doesn't exist, we'll default it to zero.

Retrieving and Updating Data with the Data Store

Including the data store requires testing the workflow. Opening the data prop will allow us to create a new store named "smurl number." This store will be used for this workflow and other workflows. While encountering an error message at this stage indicating that "data is not defined," we can easily fix it by injecting the "data" prop available under "this.data." After retesting, we should see the body displaying "number: 0," as we've defaulted to zero in case the number doesn't exist.

Creating a Separate Workflow for Real-Time Updates

To enhance the functionality of our counter, we'll create a separate workflow responsible for updating the real-time value in our data store. This new workflow will be named "Smurl Web Hook." Don't forget to deploy the changes made so far to this new workflow. We'll move on to creating another workflow, focusing on the Shopify partner integration.

Setting Up a Shopify Partner Integration

In this workflow, we'll be listening to transactions on our Shopify apps. Whenever a new app charge is created by one of your apps, our counter will be updated. Select your test Shopify account and choose the update interval of 15 minutes. Let's create this source, which is a polling source that asks Shopify every 15 minutes for any new transactions on the specified Shopify partner account.

Listening to Transactions on Shopify Apps

With the source set up, we can now try generating some test events. Once we have transactions to work with, we can proceed to create a new Node.js step. In this step, we'll inject our new store (data), specifying its type as a data store. Make sure to run the test to include the props given to this step. We can now select the required store, "smurl number," which was used in the previous workflow.

Polling Source for Shopify Transactions

To retrieve the current number before adding the next number, we'll get the number from the data store using the "data.get" method. If the number doesn't exist yet, we'll set it to zero. From there, we'll access the event using the "trigger.event" method. Next, we'll use the path "net amount.amount" to obtain the dollar amount of the transaction. To avoid decimal values, we'll round the number to the nearest whole number.

Updating the Counter with New Transactions

Now that we have the current and new numbers, we'll add them together after ensuring they are parsed as integers. To be safe, we'll use "parseInt" and "parseFloat" to avoid any potential string interpretation. Finally, we'll set the data store using the "data.set" method, specifying the attribute "number" and assigning the new number to it.

Finalizing the Workflow

With the code now complete, our workflow will run at 15-minute intervals, emitting new transaction updates and adding them to the data store under the "number" keyword. To ensure the code is functioning as expected, we should run a test. Any bugs encountered during testing can be resolved easily, improving the workflow's overall performance.

Highlights

  • Introducing IoT with the first IoT episode of Pipe Dream.
  • Utilizing a web hook trigger to communicate with the counter.
  • Creating a Node.js step to respond with JSON data.
  • Introducing the data store feature for efficient data retrieval.
  • Setting up a separate workflow for real-time updates.
  • Configuring a Shopify partner integration for transaction tracking.
  • Using a polling source to retrieve new transactions from Shopify.
  • Updating the counter with new transactions and rounding decimal values.
  • Making use of the "data.set" method to update the data store.
  • Finalizing the workflow and testing for optimal performance.

FAQ

Q: Can I use the data store feature in other workflows? A: Yes, the data store feature can be utilized across multiple workflows for efficient data storage and retrieval.

Q: What happens if a number doesn't exist in the data store? A: When a number doesn't exist in the data store, it is defaulted to zero.

Q: Will the counter update in real-time? A: Yes, the counter will update in real-time as new transactions are detected and added to the data store.

I am a shopify merchant, I am opening several shopify stores. I use ppspy to find Shopify stores and track competitor stores. PPSPY really helped me a lot, I also subscribe to PPSPY's service, I hope more people can like PPSPY! — Ecomvy

Join PPSPY to find the shopify store & products

To make it happen in 3 seconds.

Sign Up
App rating
4.9
Shopify Store
2M+
Trusted Customers
1000+
No complicated
No difficulty
Free trial