Hi Team,
I would like to add the new field in a Metric Value Property dropdown. so that we can use that property as filter for segmentation within flows and metrics.
For ex. We have existing API metrics “Add to cart” and which has pre-built properties such as basketgross, itemCount etc. so i want to create a new custom metric “Add To Cart - Custom” and add this new propety to that metric definition.
Can you please help me to achieve this ?
Thanks
Prashant
Hi
Thank you for posting in the Community!
Here’s how you can it up using Google Tag manager.
Step 1: Create a new tag in GTM:
- Log in to Google Tag Manager.
- Navigate to Tags > New.
- Name the tag (e.g.,
Klaviyo Add to Cart - Custom
).
Step 2: Configure the tag:
-
Choose tag type:
- Select Custom HTML tag.
-
Insert the Klaviyo Track API code: Add the following code to the HTML field:
<script> (function() { var dataLayerEvent = {{Event}}; var basketgross = {{BasketGross}}; var itemCount = {{ItemCount}}; var customProperty = {{CustomProperty}}; var email = {{UserEmail}}; // Ensure email is captured in your data layer // Replace YOUR_PUBLIC_API_KEY with your Klaviyo API key var payload = { "token": "YOUR_PUBLIC_API_KEY", "event": "Add to Cart - Custom", "customer_properties": { "$email": email }, "properties": { "basketgross": basketgross, "itemCount": itemCount, "custom_property": customProperty } }; var xhr = new XMLHttpRequest(); xhr.open("POST", "https://a.klaviyo.com/api/track", true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(JSON.stringify(payload)); })(); </script>
-
Customize variables: Replace
{{Event}}
,{{BasketGross}}
,{{ItemCount}}
,{{CustomProperty}}
, and{{UserEmail}}
with the appropriate GTM variables.
If the "application/json"
doesnt work. You can try with the following: "application/vnd.api+json"
Step 3: Create variables in GTM:
-
Go to variables in GTM.
-
Create the following variables based on your data layer:
- Event: Captures the type of event (e.g., Add to Cart).
- BasketGross: Captures the total basket value.
- ItemCount: Captures the number of items in the cart.
- CustomProperty: Captures your custom metric data.
- UserEmail: Captures the user’s email address (if available).
If these variables are not in your data layer, you may need to work with your developer to ensure the required data is available.
Step 4: Set up triggers:
-
Choose a trigger type:
- Use the Event trigger to fire the tag when a user adds a product to the cart.
- Example: Create a trigger that listens for an
Add to Cart
event in the data layer (e.g.,event = "add_to_cart"
).
-
Test your trigger:
- Enable GTM’s Preview mode.
- Perform an
Add to Cart
action on your website and verify that the trigger fires.
Step 5: Test and debug:
- Enable GTM’s Preview mode and verify:
- The tag fires when a product is added to the cart.
- The payload includes all the necessary properties (e.g.,
basketgross
,itemCount
,custom_property
,email
).
- Check Klaviyo’s Analytics > Metrics to confirm that the new custom event (
Add to Cart - Custom
) is recorded.
Step 6: Publish the tag:
- Once testing is complete and successful, publish the changes in GTM.
Hope that helps or else, let me know! :-)
Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov
Hi Prashant,
To add a new field to a Metric Value Property dropdown for filtering within flows and metrics, you’ll need to update the metric's definition through the API. For your example, you can create a custom metric like “Add To Cart - Custom” and include the new property by defining it in the API request payload.
If this involves complex steps or integration, feel free to reach out for further assistance.
Best regards,
Mansir
Hi Christian,
thanks for your response.
Do we need to create the custom metric first before doing this and the data will be available under the new metric ?
Hi
If possible can you please point me to the API details / documentation to update metric's definition through the API ?
You can refer to the Klaviyo API documentation for managing custom metrics here: Klaviyo API Documentation. To update a metric’s definition, you'll be working with the Metrics API to create or update events and properties. Please check the relevant endpoints for defining metrics and modifying them based on your requirements. If you need help with implementation, don’t hesitate to reach out.
Hi
You should be able to setup the tag in Google Tag Manager, which will create the metric in klaviyo, when the tag is triggered in GTM.
Hope that helps! :-)
Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov
Hi
To add a new property to a custom metric in Klaviyo and use it for segmentation:
- Create a Custom Metric: Use the Klaviyo API to create a custom event. Send data to the
/api/events/
endpoint with the custom property, like so:json
Copy code
{ "data": { "type": "event", "attributes": { "profile": {"email": "customer@example.com"}, "metric": "Add To Cart - Custom", "properties": { "basketgross": 150, "itemCount": 3, "newProperty": "value" } } } }
- Include Your New Property: Make sure the new property (e.g.,
newProperty
) is part of the event data. - Verify in Klaviyo: After sending the event, check the Metrics section in Klaviyo to see the custom metric.
- Use as a Filter: In segmentation or flows, select your custom metric and filter using the new property.
This process will let you track the custom metric and use it for segmentation in flows and reports.
You can reach out for further assistant.
Reply
Log in to the Community
Use your Klaviyo credentials
Log in with Klaviyo
Use your Klaviyo credentials
Log in with KlaviyoEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.