Skip to main content
Version: Latest

Merge Tags

Insert dynamic personalization tokens into text content that get replaced with real values at send time.

import { useRef } from "react";
import { DragbleEditor, DragbleEditorRef } from "dragble-react-editor";

function MergeTagEditor() {
const editorRef = useRef<DragbleEditorRef>(null);

return (
<DragbleEditor
ref={editorRef}
editorKey="db_your_key"
editorMode="email"
options={{
mergeTags: {
sort: true,
customMergeTags: [
{
label: "First Name",
value: "{{first_name}}",
category: "Contact",
},
{ label: "Last Name", value: "{{last_name}}", category: "Contact" },
{ label: "Email", value: "{{email}}", category: "Contact" },
{
label: "Company",
value: "{{company}}",
category: "Organization",
},
{
label: "Unsubscribe URL",
value: "{{unsubscribe_url}}",
category: "Links",
},
],
},
}}
/>
);
}

Users can insert merge tags using the merge tag button in the text toolbar.

Exclude default merge tags

Set excludeDefaults: true to remove all built-in merge tags and only show your custom tags:

mergeTags: {
excludeDefaults: true,
customMergeTags: [
{ label: 'First Name', value: '{{first_name}}', category: 'Contact' },
{ label: 'Coupon Code', value: '{{coupon_code}}', category: 'Promo' },
],
}

Update merge tags at runtime

Call setMergeTags() to replace the tag configuration without reinitializing the editor:

// React
editorRef.current?.editor?.setMergeTags({
customMergeTags: [
{ label: "First Name", value: "{{first_name}}", category: "Contact" },
{ label: "Coupon Code", value: "{{coupon_code}}", category: "Promo" },
],
});

// Vanilla JS
dragble.setMergeTags({
customMergeTags: [
{ label: "First Name", value: "{{first_name}}", category: "Contact" },
{ label: "Coupon Code", value: "{{coupon_code}}", category: "Promo" },
],
});

:::info Merge tags in links and images Merge tags also work inside link URLs. Users can insert {{unsubscribe_url}} as a button or link href from the link editor. They can also be used in dynamic image URLs to personalize images per recipient. :::

Merge tag groups

Tags are organized into collapsible groups in the dropdown using the category property. Tags with the same category are displayed together:

const customMergeTags = [
{ label: "First Name", value: "{{first_name}}", category: "Contact" },
{ label: "Last Name", value: "{{last_name}}", category: "Contact" },
{ label: "Company", value: "{{company}}", category: "Organization" },
{ label: "Plan Name", value: "{{plan_name}}", category: "Billing" },
{ label: "Amount Due", value: "{{amount_due}}", category: "Billing" },
];

You can also use nested MergeTagGroup objects for hierarchical grouping:

const customMergeTags = [
{
name: "Contact",
mergeTags: [
{ label: "First Name", value: "{{first_name}}" },
{ label: "Last Name", value: "{{last_name}}" },
],
},
{
name: "Billing",
mergeTags: [
{ label: "Plan Name", value: "{{plan_name}}" },
{ label: "Amount Due", value: "{{amount_due}}" },
],
},
];

Configuration reference

PropertyTypeDefaultDescription
excludeDefaultsbooleanfalseHide built-in default merge tags
sortbooleanfalseSort tags alphabetically within groups
customMergeTags(MergeTag | MergeTagGroup)[][]Custom merge tags to add

Method reference

MethodReturnsDescription
setMergeTags(config)voidReplace the merge tags configuration at runtime
getMergeTags()Promise<(MergeTag | MergeTagGroup)[]>Get the current merge tags list

Next steps