Collect WooCommerce purchases data using Webhooks and Integromat

How to send WooCommerce purchases into Integromat and then into Funnelytics

Scenario Overview

In the following picture we see what your scenario will look like, once we have finished setting it up.woo hook9-1

Create a Scenario in Integromat

Select the Woocomerce app as a trigger.  Choose the Watch Orders option as the trigger event.

Click the Add button and give it a name in the "Create a connection" window that comes up. Then add all the info required. Woocommerce-WebHook-Integromat (1)

You can find the Consumer Key and the Consumer Secret by creating a REST API in your Woocommerce settings panel.

Integromat will automatically determine the structure of the data. Be sure to test your funnel so setting up the next steps will be easier.

Add the Iterator tool

The Iterator tool allows your Integromat scenario to read multiple products' info nested inside your data coming from Woocommerce.

Step 1. Click on the green "Cog" icon you can find at the bottom of your scenario page.

Step 2. Select "Iterator".


Step 3. Go ahead and connect it to your Woocommerce trigger. Once done, you will be able to select the element that contains the products purchased so that Integromat can collect the information and send it to Funnelytics. The element you have to look for is named Line items.

Once added, it will be displayed in the Iterator window as 9. Line items [].

Note: The numbers you will see on the elements once selected, are there to make it easier to understand where that data is coming from.

These numbers correspond to the number you see under each module.

In this example, the WooCommerce module has the number 9 so every element coming from it will have a 9 at the beginning.

 

iterator woo

Add the Aggregate to JSON module

Now that you have made all the purchased products' data available to Integromat, let's ask it to put them in a way that the Funnelytics endpoint will easily digest.

To do this you will have to add an Aggregate to JSON module.

Step 1. Click on the little "+" icon on the bottom of the scenario page.

Step 2. Type JSON in the window that pops up,

Step 3. Select the JSON icon

Step 4. Then hit Aggregate to JSON.

Configure the Aggregate to JSON module

Configuring this module is quite easy thanks to the built-in generator, which lets you create the layout by making it read the structure of the final code we want to create.

Step 1. Start by selecting the Source of the data from the dropdown menu, which will be the Iterator.
Step 2. Then click on the Add button to create a new data structure.

Step 3. Give it a name.

json setup

Step 4. Click on Generator.

Step 5. In the new window, select JSON in the "Content-type" dropdown menu. 

Step 6. Paste the following code in the "Sample Data" field.

{
"product_name": "my product name",
"product_id": "my product id",
"total": 0
}

Integromat will read the JSON code and will populate the "Specification" section with the three elements we need and their value type.

Json Woo

The last step is to go back to the first window of the Aggregate to JSON module and select which values shall fill those fields. To do this just click on the field that needs to be filled and select the value from the pop-up window.

Element Value
product_id Product ID
produc_name Name
total Total

Note: Every Integromat module output value will inherit the module's color so that it will be easier to spot the correct element when recalling them in a further step.

Add the HTTP Request

Let's get to the last piece of our puzzle, the HTTP Request module.

To add the module, we will once again click the little "+" icon that appears at the bottom of the scenario page, however, in this case, we will search for "HTTP", and the action will be Make a Request.

Woocommerce-http

Configure the HTTP Request module

Step 1. Add https://track.funnelytics.io/events/commerce to the URL field. 

Step 2. Select POST as the Method.

Step 3. Add two headers as detailed in the table below:

Header Name Value
1 Content-Type application/json
2 Authorization Your Funnelytics API key (you can find it in your workspace settings tab)

Step 4. Select Raw as "Body Type"

Step 5. Set JSON (application/json) as the "Content type".

Step 6. Lastly, in "Request content"  paste the following code and enter your data between the empty quotes ""

{
"email": "",
"datetime": "",
"items":
}

Woocommerce-http3

Click the "Request Content" field to reveal the data mapping pop-up.

Woocommerce-http2

Step 1. In the Woocommerce elements look for the one that contains the User's Email and add it between the quotation marks in front of the "email": line. In my case here is 9. Billing: Email

Step 2. Again, in the Woocommerce elements, look for the property that contains the order creation timestamp and add it between the empty quotation marks in the "datetime": line.

Step 3. Add the Aggregate to JSON output in the "items": line.

Note: be aware that Funnelytics' endpoint will accept only timestamps in the ISO 8601 format (Wikipedia): 2021-03-29T09:58Z (UTC example)

If your payment process/cart solution does not send out time data formatted this way you can always format it yourself, by adding this bit of code instead of the single time element,

"{{parseDate(Woocommerce Date Created; "YYYY-MM-DDTHH:mm:ss"; "Timezone")}}"

The Woocommerce Date Created is the one containing the order creation timestamp.

The Timezone (if needed) has to be chosen in this list only otherwise it won't be recognized by Integromat: TZ Database Name.

Here below you can see a real-case example:

"{{parseDate(1.time; "YYYY-MM-DDTHH:mm:ss"; "America/Sao_Paulo")}}"

 

Congratulations! You have completed setting up your WooCommerce scenario!

Next Steps

Now that everything is set up, let's clear our cookies (or use another browser) and run again through our funnel in test mode, complete a test purchase and make sure that it's working as expected.

NOTE: If you are using Stripe, you shall test it in Live mode otherwise no webhook will be fired in test mode

 

If you have any questions or need further clarification with setting up actions, remember to reach out to our support team anytime by clicking the support icon in the bottom-right corner of your dashboard, or emailing us at support@funnelytics.io we are always ready to assist you!