Tutorial

Solution Recipe | Troubleshooting Event Data with ChatGPT

  • 14 March 2023
  • 1 reply
  • 273 views
Solution Recipe | Troubleshooting Event Data with ChatGPT
Userlevel 7
Badge +36

Hi Developer Group!

 

Please enjoy this installment of our Solution Recipe series, brought to you by our very own @ninaephremidze!

 

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers & technically-advanced users.

 

WHAT YOU’LL LEARN:

How to troubleshoot the ingested data in Klaviyo using ChatGPT, the brainchild of OpenAI.
More specifically, we will troubleshoot the payload and properties we want to segment in Klaviyo’s UI. Later, we will modify the event data with ChatGPT, so that the nested properties become flattened, which will then let us create segments in Klaviyo.

 

WHY IT MATTERS:

OpenAI is a company that has released AI systems which have gotten a lot of attention from the public in general. Particularly, tools such as ChatGPT are considered to be revolutionary and perhaps the invention of the century. ChatGPT has many benefits for people in different fields. It can be an especially handy tool for professionals in the tech industry. The tool helps generate personalized responses to user inquiries, allowing developers to tailor the chatbot to their particular use case, whether it’s debugging the code, troubleshooting errors, or understanding the source code.

 

LEVEL OF SOPHISTICATION: Moderate

 

INTRODUCTION

 

You may have already heard about the release of OpenAI on various news sources, social media, tech channels, etc., and you may be curious what all the hype is about.


First of all, let’s demystify OpenAI.


OpenAI is a company that focuses on creating Artificial Intelligence tools and conducts research in various fields. It aims to contribute to machine learning, robotics, and humanity as a whole.


ChatGPT (short for “Generative Pre-Training Transformer”), the main tool discussed in this blog, is a type of language model developed by OpenAI designed to generate human-like text by predicting the next word in a sequence based on the context of the words that come before it.

 

 

There are a few other tools that are part of OpenAI, such as Playground, DALL-E, and Gym, but in this article, we will be focusing primarily on GPT (chat.openai).

 

CHALLENGE
Now that you have a general understanding of OpenAI and ChatGPT, let’s see how the tool can be used with Klaviyo to help troubleshoot technical requests.


There are a few ways one can utilize ChatGPT and Klaviyo together. For example, it can help debug one’s code, explain what the given errors mean in Klaviyo, and advise on how to change them.


Despite ChatGPT’s “Thomas Edison” moment, it doesn’t come without drawbacks. In other words, ChatGPT helps modify and troubleshoot the provided source code, but it is up to a developer to have the fundamental background of how things work in order to be able to fully assess the adequacy of responses and ask the right questions.


When experimenting with ChatGPT, make sure to test the output for code, especially before pasting it right away.


Here is one of the code examples shown below:

 

 

 

INGREDIENTS

 

You will need the following ingredients in order to troubleshoot with ChatGPT:

  • Klaviyo account
  • An OpenAI account — sign up while it’s still free
  • Postman/Terminal or Klaviyo SDK if you have a library installed
    Note: I will be using Postman in this blog post
  • The payload you are trying to troubleshoot/debug

 

Once you have an account for both platforms, head to ChatGPT and type in a random question for fun.

 

 

 

INSTRUCTIONS

 

What We Are Trying to Solve: Let’s say you made an API call using the create event endpoint to ingest the placed order data into your Klaviyo account (payload below), so you can create a segment, based on the queried properties. However, it looks like the properties you wanted to segment aren’t showing up in the drop-down menu in Klaviyo, despite the success message in Postman.

 

Let’s ask ChatGPT for help!

 

Step I

Here is the payload sent via Postman for the Placed Order event:
https://docs.google.com/document/d/1GisFZWGVuSiL9LCQYpK8yACQJD_1F4sPEpvOSvdCjvI/edit


Note: Due to the length of the event data, it’s stored in the google docs above.

 

Step II

The Postman response below shows a success message, meaning that the payload went through successfully:

 

Now let’s check the queried data in our Klaviyo account to see what it looks like there.

 

Step III
Below, we can see that the placed order event has been successfully ingested into Klaviyo’s UI:

 

 

Step IV

Let’s manually Create a Segment based on the placed order properties passed via the event endpoint for the “ProductID”, “SKU”, “ProductName”, and “Quantity” attributes listed in the payload.


It looks like the properties we would like to segment by are not showing up in the segment dropdown, despite the fact that Postman showed a success message, and we can see those properties in the metrics tab:

 

 

Step V
This is a good time to utilize ChatGPT and troubleshoot our code.


As noted earlier, in order to debug the code with ChatGPT we need to have prior knowledge of the code/how Klaviyo works, so that we can ask ChatGPT the right questions and understand the accuracy of the answers.

 

After taking a closer look at the properties by which we want to segment, it looks like we’ve constructed the JSON payload to represent the properties we’d like to segment by as objects in the array, meaning that they are nested. In other words, those objects are inside another object.

 

Here is what ChatGPT answered when I asked why I can’t segment the properties:

“It looks like the properties for “ProductID”, “SKU”, “ProductName”, are nested within the “Items” property, which is in turn nested within the “properties” property.
According to the documentation in Klaviyo, you need to have a top-level property in order to be able to segment the attributes in Klaviyo. This means that, in order to segment based on these properties, we would need to flatten the payload so that all properties are at the top level.”

 

To paraphrase, instead of having the “Items” property contain an array of objects with nested properties, we would need to separate the top-level property for each item property, such as “ProductID_1”, “SKU_1”, “ProductName_1”, etc. for the first item, and “ProductID_2”, “SKU_2”, “ProductName_2”, etc. for the second item.

 

How do I know?


With the help of OpenAI’s abracadabra magic displayed below:

 

When I asked OpenAI to provide the flattened payload it did not generate the entire payload in the response, and ended at the shipping address:

 

ChatGPT helped flatten the entire payload, but the response removed all the required attributes such as profile or ID, and left out the curly braces in the payload.

I still couldn’t segment the ProductID, SKU, and ProductName, even though ChatGPT confirmed they are all top-level:

 

“It looks like all of the properties in the payload are top-level. However, the SKU property is nested within the Items array. In order to segment on the SKU property in Klaviyo, you would need to include it at the same level as the other properties, rather than nested within the Items array. You can do this by flattening the structure of the payload, so that each item in the Items array is represented as a separate top-level property. This will allow you to segment on the SKU property in Klaviyo.”

 

Step VI
After pushing back and asking the question differently to achieve the desired result, ChatGPT was a lot closer, but still didn’t provide the entire payload, skipping the unique id:

 

Step VII

Several attempts later, ChatGPT provided the finalized results without shortening the event data and flattening the JSON.


As you can see, it took a few attempts and modifications to get there though:

 

Despite some back-and-forth communication and pushback with ChatGPT, the good news is that it can still give an idea as to why some properties weren’t segmentable, and advised on how to reformat the payload to make it all top-level.

 

Step VIII
The final step entailed asking ChatGPT to reformat the event data so that I could directly copy-and-paste into Postman and use the Create Event endpoint.


At first, the given results weren’t complete.

 

When copy-pasting the given result into Postman, I got the following generated error: “One of `attributes`, `relationships` or `id` must be included in the request payload.”

 

I asked ChatGPT to help fix the above error, it did resolve that issue, but another error prevailed. “‘profile’ is a required field for the resource ‘event’.”, meaning that it removed the profile from the payload:

 

After the above error-correction by ChatGPT, Postman generated a success message, meaning that the modified payload went through and should have identified all the properties as top-level.

 

Below is the final version of the payload:
https://docs.google.com/document/d/1BkPWxg0wsaUgVbHrDKezLyYTFkNr2hq8mdo9cMOn9LA/edit

 

Success message from Postman:

 

ChatGPT confirming that all the properties are top-level:

 

Step IX
Let’s see if we can segment by all of the properties that we couldn’t before in the Klaviyo UI


It looks like we can now segment by the SKU, product Name , Product ID properties that were nested before:

 

CHATGPT LIMITATIONS

  • Limited in the ability to understand context, making it difficult for ChatGPT to answer more open-ended questions
  • Relies heavily on training data to generate accurate responses, making it difficult to personalize the chatbot for each user’s particular needs
  • Still early in its development, so it may suffer from unexpected errors or inaccuracies
  • The data only references up until 2021, so it is recommended to double check Klaviyo’s documentation to ensure developers are following best practices and the most recent information. Especially since we have had new endpoints come out in 2022 and more coming in 2023
  • While ChatGPT can answer accurately on most occasions, it’s still advised to consult the documentation or the community if you continue to run into issues using the tool

 

FINAL THOUGHTS

In this recipe, we learned how to use ChatGPT to troubleshoot the code we’d like to ingest in Klaviyo and convert the nested properties into top-level properties so they are segmentable in Klaviyo.

 

The major takeaway from this test is that, although it’s incredibly efficient, we still can’t rely blindly on the answers generated by ChatGPT. One would need prior knowledge of Klaviyo and have developer experience in order to ensure that the responses are accurate.

 

By using chatopenai.com, developers can quickly troubleshoot code and debug payloads. As seen in this recipe, ChatGPT can help users flatten payloads to make them segmentable in Klaviyo, enabling users to create more targeted segments and personalize experiences for their customers.

 

It can certainly help save time and effort when working with Klaviyo and other third-party technologies.

 

ChatGPT is a powerful tool that can help developers and tech-savvy users troubleshoot code and debug payloads more efficiently.

 

Overall, ChatGPT is a great tool to have in your arsenal when it comes to troubleshooting code and debugging payloads.


As noted earlier, you still need to have a fundamental knowledge of how the code works, what tools to use, and what Postman is, but ChatGPT can certainly help you save time and point you in the right direction in a matter of seconds.


1 reply

Userlevel 5
Badge +18

Ask me how I know it can do this for custom PHP integrations between custom WooCommerce fields and Klaviyo too. ;-) 

Reply