Hello @robdentonrachio,
Klaviyo’s template language (based on Django’s Liquid) does not support direct variable assignment using {% %}
tags. However, you can extract values from the split array inline using {{ }}
.
Try this:
Customer ID: {{ event.URL | split: '/' | slice: 4 }}
Event ID: {{ event.URL | split: '/' | slice: 6 }}
This extracts the 5th (CUSTOMERID
) and 7th (EVENTID
) elements from the split array.
If you're using a Python custom action, you’ll need to process the URL in Python and pass CUSTOMERID
and EVENTID
as separate properties in the Klaviyo event payload, then reference them in the email as {{ event.CUSTOMERID }}
and {{ event.EVENTID }}
.
Thank you. Unfortunately, the slice filter removes the latter part of the list at the given position, leaving the front half of the list so that’s not going to work. However, the lookup filter does work if you use the index. For future reference, the syntax looks like this:
{{ event.URL | split: '/' | lookup: 4 }}
Your response does lead me to another question, though. Regarding the Python custom action you say, “you’ll need to process the URL in Python and pass CUSTOMERID and EVENTID as separate properties in the Klaviyo event payload.” I am able to process the URL in Python, but how do I pass the variables back as separate properties in the Klaviyo event payload?
I’ve tried setting eventt"data"]n"attributes"]t"event_properties"]o'CUSTOMERID'] = CUSTOMERID and returning event. This does not seem to work.
@robdentonrachio I appreciate your insights on the lookup filter—you're absolutely right, and that’s a great approach. Thanks for sharing that!
Regarding your question about passing variables in the Klaviyo event payload, I recently completed a similar project for another client and can definitely help you with this. The key is ensuring that the event properties are structured correctly before sending the payload.
Here’s the recommended structure:
event_payload = {
"data": {
"type": "event",
"attributes": {
"event_name": "Your Event Name",
"event_properties": {
"CUSTOMERID": CUSTOMERID,
"EVENTID": EVENTID
}
}
}
}
Make sure the request is properly formatted when sending the event to Klaviyo. If you’re using a POST request to Klaviyo’s API, ensure that the content type is set to application/json and that the payload is correctly encoded.
If you're still running into issues, I’d be happy to take a closer look and assist further. Let me know how you'd like to proceed!
Ah, I see. So a new event payload is required, you can’t modify the existing event payload in the current flow. Ok, thanks for all your help!
@robdentonrachio
Yes, exactly! A new event payload is required since Klaviyo doesn’t allow modifying past events. Glad I could help! Let me know if you need any further clarification or assistance with the implementation.