Marketing Cloud Next: Dynamic images in Email, 2 ways that work

MC Next - Tips from the Trenches #003
Learn two ways to show dynamic, per-record images in Marketing Cloud Next emails. Image component with Merge Field or custom HTML, plus Data Graph/field tips

In a previous article about Repeaters for Emails in Marketing Cloud Growth and Advanced, we took the example of a boat rental company, sending an email listing previous reservations.

The reservations are part of the Data Graph and they contain the image URL to display for each reservation record. 

In this article, we will focus on sending an email, presenting the current reservation model. This is what we are trying to achieve (we’ll focus on displaying the dynamic image, not on the body copy here):

An email presenting the specific rented boat model

Method #1 – Using the default Image Component

So, the first step, once the Email is created, is to add an Image Component into the canvas. You can drag it from the left sidebar, under Media or click the + sign in the canvas.

Adding the image component to the canvas

Once the email is in the canvas, we are presented, on the right sidebar, in the Select Image Source section, the option to add an image from the CMS (a static one), or using a Merge Field. It is this latter option we will choose, since the image URL is stored as field in our Data Graph.

Selecting the Merge Field option to insert a Dynamic Image

So, we click the Add Merge Field option, and navigate through our Data Graph, to reach our Image URL.

Searching for our Image URL in the Data Graph

But, no luck, it is not presented, even though actually in the Data Graph (Boat Thumbnail):

Data Graph, an image URL is there

So, why can’t we add it as Merge Field in the image Component? Well, the answer to this is that the URL format is not supported, it needs to be a text field. In Salesforce, our field for storing the images in a reservation is an URL type, when creating the DSO we just used the defaults.

So, to solve this, we’ll create a new Formula field in our DSO, basically a copy of the URL, but with the Text Format. In our example, we call it Boat Preview, and declare it that way:

Our image URL copied as text Formula Field

Once done, we need to:

  1. Map that text Field to a new Field in our DMO (same type)
  2. Add the Field in the Data Graph, by editing it
  3. Force the evaluation of new the Formula Field (the simplest is to mass update the reservations and manually trigger a refresh of the DSO)
  4. Force the refresh of our Data Graph

We then have this is for a specific reservation record:

A text field is added to our Data Graph, containing the address of our image

In case you wonder, this images are stored in the CMS, and their addresses stored in Salesforce are obtained by following the 6th recipe of our CMS optimisations article.

Also, if your record is the DMO, but not in the Data Graph, this is probably due to the fact that Engagement DMOs records older than 30 days are ignored by the Data Graph.

Then we can go back to our Email Editor, and now see with the text Fields, which we will use.

Boat preview is available in the Data Graph

So let’s insert it. Depending on wether there can have multiple records of reservations, you need to select which record to display (or use Repeaters in the exact same way);

Adding the text Merge Field as the source of the image
Accepting the default API name (_4 as our 4th attempt here)

We are all set, now, to Preview our work. Do not forget to Save the Email before previewing it, otherwise the Merge Field disappears. Et voilà 😎

Our image for a given reservation
Another reservation from another Contact, yes, this is Dynamic

Method #2 – Using an HTML component

In this method, we don’t drag an Image Component into the canvas, but an HTML component, in which we will add the Dynamic Image. This gives you the complete control on how you want the image to look.

Adding a default HTML component to the canvas
Our goal is to replace the empty string with the Merge Field. There is a Add Merge Field button below the component, you may need to scroll the right sidebar to display it. Then, we will enter the following code (adjust to your needs) in the HTML component:

<img src=”” width=”100%” />

The steps are exactly the same as the one described in the first method. But, doing so the HTML complains that the src attribute should contain a value starting with “https://”. Obviously, this is made for static image. Hopefully, it also supports Dynamic URLs, but we’ll need to do some extra work. 

The HTML component complaining the src attribute is not compliant

First, let’s make the component happy by adding the correct scheme at the beginning of the src attribute.

But, doing so, the image would not display, as the URL would actually be malformed (starting with two “https://” schemes).

To tackle this, we’ll simply edit the definition of our text Formula field (or create a new one) by using the following Formula:

				
					REPLACE(sourceField['Boat_Thumbnail__c'], 'https://', '')
				
			

We can ensure this works as intended with the Test Button of the Formula Fields (enter a value, click test and see the result in the Output section).

The scheme is removed from the URL

We then to go through the exact same steps as the ones from the first method to refresh our Data Graph, so now the URL has the correct formatting to be handled by the HTML component.

Once done, we don’t forget to save our work before previewing the email for a given reservation. It works too 😎

Dynamic Image inserted via the HTML component

Be informed when we publish new content or have any questions? Join the TAM Slack workspace ↓

Share the Post:

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Join us on Slack

Your questions, answered.
Get our latest articles.