SFMC Pro Tips: From Catalog Evolution to Flash Sales Swapping images in SFMC live emails.

There are several ways, SFMC emails can be personalized. This blog post explores few methods to seamlessly swap images in live SFMC emails.

You might be asking why I want to swap images in emails, which is already designed dynamically. Consider below scenarios:

  • Catalog Evolution: Update product images in your catalog and ensure your audience always sees the latest offerings.
  • Timely Promotions: Showcase limited-time offers and promotions with dynamic hero images.
  • Seasonal Adaptations: Align your email visuals with changing seasons for a more relevant experience.
  • New Product Launches: Generate excitement by featuring new products with dynamic images.
  • Special Events: Highlight relevant products for specific occasions and holidays.
  • Flash Sales: Create urgency and entice subscribers with visually compelling offers.

Dynamic Image Swapping Techniques:

MCP Open time emails:

Open Time Emails leverage personalized content based on the moment a recipient opens the email.


Here's how it works:

  • Design an email template and create item templates for personalized content sections.
  • Generate HTML code to embed in existing email campaigns.
  • When a recipient opens the email, Marketing Cloud Personalization dynamically generates personalized content based on real-time data, past behavior, and recipient preferences.


Changing just the image:

SFMC offers a feature allowing replacement of existing images while preserving all other parameters. This can be done on UI or via API using the PUT method on the endpoint /asset/v1/content/assets/{id}.


Using this:

  • An image can be replaced from the UI at any point in time without touching the scheduled emails.
  • An external system can change the images in SFMC.
  • An automation using an SSJS script can change images fetching the image content from SFMC itself or an external source via API.

Note: ESPs' image management and caching mechanisms significantly impact how all send time personalization techniques above, with Apple being proactive by pre-downloading images before email opening.


Even salesforce help documentation here says the recommendations for apple email users are calculated at send time.


AMPscript for Send Time Image Changes:

This code snippet leverages the ContentImageByKey() function within AMPscript to dynamically insert images into emails based on the customer's key.


Here's how it works:

  • The code searches for an image in Content Builder with today's date as part of the image's CustomerKey (not in name).
  • If an image is found, the function retrieves its path and inserts it into the email using the img tag.
  • If no image is found for the specific customer key, a fallback is placed in the email.

These techniques can help in changing images at certain dates (while holding a default image for everyday) on automated campaigns, like journeys, automations, or triggered sends.


Using this:

  • This AMPscript block enables marketers to change images at certain dates, such as special days, holidays, or promotional events, within automated campaigns like journeys, automations, or triggered sends.
  • This approach can be further enhanced by using a data extension that stores image keys with associated from and to dates. AMPscript can then look up these dates and dynamically change the image accordingly.

Code Sample for changing image by Date in Customer Key:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%%[
   /*
      <h2 style="color: #34495e;">
         This section pulls the image by customer key
         <strong><u><i>AbandonCategory_Email1_Hero_MMDDYY</i></u></strong>
      </h2>
      <h2 style="color: #2980b9;">
         The email is located at
         <strong><u><i>Content Builder>01 Emails>01F IS>Abandon Category>Abandon Category V2>Email 1</i></u></strong>.
         Please upload the image there as required.
      </h2>
   */
   var @imageKey, @imageKeyFallBack, @imageTag, @today, @formattedDate
   set @imageKeyFallBack = "AbandonCategory_Email1_Hero_Default" 

   /* Get today's date and format it as MMDDYY */
   set @today = Now(1)
   set @formattedDate = FormatDate(@today, "MMddYY")

   /* Frame @imageKey as AbandonCategory_Email1_Hero_MMDDYY */
   set @imageKey = Concat("AbandonCategory_Email1_Hero_", @formattedDate)
   set @imageTag = ContentImageByKey(@imageKey, @imageKeyFallBack)
]%%

<table width="100%" cellspacing="0" cellpadding="0" role="presentation">
   <tr>
      <td align="center">
         %%=Replace(@imageTag,'>',' alt="Take 5% off full priced items" height="190" width="570" style="display: block; padding: 0px; text-align: center; height: 190; width: 570; border: 0px;" >')=%%
      </td>
   </tr>
</table>


Code Sample for Changing image by dates mentioned in a DE:

We will have a Data Extension named Swap_Images with the following fields:

Name

Data Type

Length

Primary Key

Nullable

Default Value

Journey_Name

Text

100

Yes

No

-

To_Date

Date

-

No

Yes

-

Image_customer_Key

Text

50

No

Yes

-

From_Date

Date

-

No

Yes

-

Current_Date

Date

-

No

Yes

-


The code below displays the image based on customer key mention in the above table when the current date is between from and to dates.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%%[
/*
   To determine the image displayed here, add a record into the <i style="color: #2980b9;">Swap_Images Data Extension<br/>
   located at Data Extensions > Swap Emails</i>.<br/><br/>
   Make sure the details are as below:<br/>
   <i style="color: #2980b9;">
   Journey_Name: asdasX<br/>
   From_Date: [Your From Date]<br/>
   To_Date: [Your To Date]<br/>
   Image_customer_Key: [Your Image Customer Key]<br/><br/><br/></i>
*/
]%%
%%[
/* Define the name of the Data Extension */
var @myDEname
set @myDEname = "Swap_Images"
/* Replace with the actual Journey Name */
var @journeyName
set @journeyName = "asdasX"
/* Retrieve data with lookup based on the Data Extension name and filter criteria */
var @data
set @data = LookupRows(@myDEname, "Journey_Name", @journeyName)
/* Check if there is a matching row in the Data Extension */
if RowCount(@data) > 0 then
 set @row = row(@data, 1)
  /* Convert From_Date and To_Date to AMPscript format */
  var @fromDate, @toDate
  set @fromDate = FormatDate(Field(@row, "From_Date"), "s")
  set @toDate = FormatDate(Field(@row, "To_Date"), "s")
  /* Get today's date in AMPscript format */
  var @today
  set @today = FormatDate(Now(), "s")
  /* Check if today falls between From_Date and To_Date */
  if @today >= @fromDate AND @today <= @toDate then
    /* If it does, get the Image_customer_Key and store it in a variable */
    var @imageCustomerKey
    set @imageCustomerKey = Field(@row, "Image_customer_Key")
    set @imageTag = ContentImageByKey(@imageCustomerKey, "AbandonCategory_Email1_Hero_Default")
  else
    /* If today is not between From_Date and To_Date, set a fallback Image_customer_Key */
    set @imageTag = ContentImageByKey("AbandonCategory_Email1_Hero_Default", "AbandonCategory_Email1_Hero_Default")
  endif
else
  /* Handle the case when there is no matching row in the Data Extension */
  set @imageTag = ContentImageByKey("AbandonCategory_Email1_Hero_Default", "AbandonCategory_Email1_Hero_Default")
endif
]%%

%%=v(@fromDate)=%%
%%=v(@toDate)=%%
%%=v(@today)=%%
<table width="100%" cellspacing="0" cellpadding="0" role="presentation">
  <tr>
    <td align="center">
      %%=Replace(@imageTag,'>',' alt="Take 5% off full priced items" height="190" width="570" style="display: block; padding: 0px; text-align: center; height: 190; width: 570; border: 0px;" >')=%%
    </td>
  </tr>
</table>

No comments:

Post a Comment

Powered by Blogger.