:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): accept the unsubscribe_url liquid tag in the email editor (#123315)
Harley Alexanderbfb6ac342c09
diff --git a/frontend/src/lib/utils/liquid.test.ts b/frontend/src/lib/utils/liquid.test.tsindex 420a960a60c8..e75279edcadd 100644--- a/frontend/src/lib/utils/liquid.test.ts+++ b/frontend/src/lib/utils/liquid.test.ts@@ -24,6 +24,16 @@ describe('LiquidRenderer', () => {expect(LiquidRenderer.render('{{ amount | currency: "USD" }}', { amount: 1234.5 })).toBe('$1,234.50')})+ it.each(['{% unsubscribe_url %}', '{%- unsubscribe_url -%}'])(+ 'renders the Customer.io tag %s like the unsubscribe_url variable',+ (tag) => {+ const unsubscribe = { unsubscribe_url: 'https://example.com/preferences?token=abc&team=1' }+ expect(LiquidRenderer.render(`<a href="${tag}">x</a>`, unsubscribe)).toBe(+ LiquidRenderer.render('<a href="{{ unsubscribe_url }}">x</a>', unsubscribe)+ )+ }+ )+it('treats an unparseable expression as unresolved rather than throwing', () => {expect(LiquidRenderer.resolves('person.properties[', context)).toBe(false)})diff --git a/frontend/src/lib/utils/liquid.ts b/frontend/src/lib/utils/liquid.tsindex 844c1509bec3..af2c9143ef4d 100644--- a/frontend/src/lib/utils/liquid.ts+++ b/frontend/src/lib/utils/liquid.ts@@ -1,5 +1,5 @@// Lazy load liquid library-import { Liquid, Output, Template } from 'liquidjs'+import { Context, Emitter, Liquid, Output, Tag, TagToken, Template, TopLevelToken } from 'liquidjs'const LIQUID_REGEX = /\{\{(.*?)\}\}|{%(.*?)%}/g@@ -105,6 +105,23 @@ const formatCurrency = (value: unknown, first?: unknown, second?: unknown): unknreturn currencyFormatter(first, second)?.format(amount) ?? value}+// Copy of the tag in nodejs/src/cdp/utils/liquid.ts, so the editor accepts what the worker sends.+// Customer.io templates write the unsubscribe link as a tag, `{% unsubscribe_url %}`, where we expose a+// variable. The tag renders `{{ unsubscribe_url }}`, so it gets the same escaping as the variable and+// renders empty when the send has no unsubscribe URL.+class UnsubscribeUrlTag extends Tag {+ private readonly templates: Template[]++ constructor(token: TagToken, remainTokens: TopLevelToken[], liquid: Liquid) {+ super(token, remainTokens, liquid)+ this.templates = liquid.parse('{{ unsubscribe_url }}')+ }++ *render(ctx: Context, emitter: Emitter): Generator<unknown, void, unknown> {+ yield this.liquid.renderer.renderTemplates(this.templates, ctx, emitter)+ }+}+// NOTE: This should be moved to common package but currently is a copy of nodejs/src/cdp/utils/liquid.tsexport class LiquidRenderer {private static _liquid: Liquid | null = null@@ -118,6 +135,7 @@ export class LiquidRenderer {templates: {},})this._liquid.registerFilter('currency', formatCurrency)+ this._liquid.registerTag('unsubscribe_url', UnsubscribeUrlTag)}return this._liquid}diff --git a/products/workflows/skills/designing-email-templates/SKILL.md b/products/workflows/skills/designing-email-templates/SKILL.mdindex 7f46b0fcb3f3..8a0284b28f71 100644--- a/products/workflows/skills/designing-email-templates/SKILL.md+++ b/products/workflows/skills/designing-email-templates/SKILL.md@@ -30,6 +30,7 @@ Marketing emails must include an unsubscribe link — render it with the built-i```(`{{ unsubscribe_url_one_click }}` is also available for one-click list-unsubscribe flows.)+A template written for Customer.io can keep its `{% unsubscribe_url %}` tag, which renders the same link as `{{ unsubscribe_url }}`.Output is HTML-escaped by default, so a value renders as text even when it contains markup: