Skip to main content

Is there any way to identify a campaign or flow message within the message itself through the use of some template variable? Our app provides personalized recommendations within an email and it would be very helpful for external tracking to be able to pass this id to our system and to GA4 (I recognize I can add it to the utm params but that doesn’t help me to track our product recommendations and personalizations within the email on open).

Hello ​@obviyo , 

You can use Klaviyo's event.extra data or message.id as a unique identifier within your email template. To track personalized recommendations effectively, consider embedding a custom variable within your recommendation links, such as:

?rec_id={{ event.extra.rec_id }}

For GA4 tracking, you might pass the ID as a custom event parameter using Klaviyo’s Webhooks or API to log interactions. If implementation gets complex, feel free to reach out for guidance.

 


Hi ​@MANSIR2094 ,

I tried to use {{ message.id }} in email but it doesn’t ever seem to print out anything. Is there a certain condition that needs to be met before that works or does that only work in certain types of emails?


@obviyo {{ message.id }} is only available in flow emails, not campaigns. If you're using it in a campaign, it won't populate. For campaigns, you can try {{ campaign.id }} instead.

 

If you need a consistent identifier across both, consider passing a custom variable via event data for flows or using UTM parameters for campaigns. Let me know if you need help setting this up!

 


@MANSIR2094 Hmm, I tried {{ message.id }} in a flow email and it didn’t print out anything for me. I just threw it into the source of a text block like so:

<div>{{message.id}}</div>

Anything I’d be missing there?


@obviyo ,Klaviyo doesn’t render Liquid variables inside raw HTML elements like <div>. Instead, try placing {{ message.id }} in a standard text block without HTML.

 

If you must use it in HTML, wrap it in a Klaviyo variable tag:

{% capture message_id %}{{ message.id }}{% endcapture %}<div>{{ message_id }}</div>

 

Let me know if you need further troubleshooting!

 


Hey ​@obviyo,

Did you get this figured out? I believe that {{ email_message.id }} would dynamically pull in the campaign’s ID. Can you try that one and let me know how it goes? Also, when you tried {{ campaign_id }}, did that work?

Let me know if this works, and if I can help out with anything else.

-Byrne


Hi ​@Byrne C,

{{ email_message.id }} seems to work well to pull the campaign id and flow message id. Thanks for that. None of the other values seemed to work.

Just curious, is there any variable that will pull the flow_id in?

Thanks for this answer,

-Mark