I am working on create a dynamic email using a contacts engagement on a campaign (using the case create date to create a ranking). The goal of the email is to show the content that the contact is more likely to engage with at the top and the least likely at the bottom based on past data. The content from the email is being pulled through a DE. If we do not have engagement data, it should pull the priority order than has been set in the content DE. I have created a separate DE that includes the content and ranking for contacts that have engagement data.
The emails contain up to six blocks that each subscriber should get. These do not usually align with the campaign engagement, if they do not align, they still need to be shown but lower in the email.
Here is my ampscript code that is pulling in the data:
@Specialty, @Headline, @BodyCopy, @PriorityOrder, @CategorySET @numRowsToReturn = 0 /* O means null, max 2000 */SET @rows = LookupOrderedRows("Engagement_DE", @numRowsToReturn, "Priority_Order ASC, Specialty, Headline, Body_Copy, Category" , "Region_Id", @EnterpriseAttributeRegionID)SET @rowCount = rowcount(@rows)IF @rowCount > 0 THEN FOR @i = 1 TO @rowCount DO SET @row = row(@rows,@i) SET @Specialty = field(@row,"Specialty") SET @Headline = field(@row,"Headline") SET @BodyCopy = field(@row,"Body_Copy") SET @PriorityOrder = field(@row,"Priority_Order") SET @Category = field(@row,"Category")]%%%%=treatascontent(v(@Specialty))=%%<br>%%=treatascontent(v(@Headline))=%%<br>%%=treatascontent(v(@BodyCopy))=%%<br>%%=treatascontent(v(@Category))=%%%%[NEXT @iELSE /* If content is not found in engagement DE then pull from content DE */ SET @rows = LookupOrderedRows("Content_DE", @numRowsToReturn, "Priority_Order ASC, Specialty, Headline, Body_Copy, Category" , "Region_Id", @EnterpriseAttributeRegionID)SET @rowCount = rowcount(@rows)IF @rowCount > 0 THEN FOR @i = 1 TO @rowCount DO SET @row = row(@rows,@i) SET @Specialty = field(@row,"Specialty") SET @Headline = field(@row,"Headline") SET @BodyCopy = field(@row,"Body_Copy") SET @PriorityOrder = field(@row,"Priority_Order") SET @Category = field(@row,"Category")]%%%%=treatascontent(v(@Specialty))=%%<br>%%=treatascontent(v(@Headline))=%%<br>%%=treatascontent(v(@BodyCopy))=%%<br>%%=treatascontent(v(@Category))=%%%%[NEXT @iELSE /* @rowcount */ ]%%%%[ENDIF ENDIF /* @rowcount */ ]%%
Engagement DE:Subscriber | Speciality | Headline | Body_Copy | Priority_Order | Region-----------|--------------|----------|-----------|----------------|--------1 | Speciality 1 | Headline | Body copy | 1 | 41 | Speciality 2 | Headline | Body copy | 2 | 41 | Speciality 3 | Headline | Body copy | 3 | 41 | Speciality 4 | Headline | Body copy | 4 | 4
Content DE:Speciality | Headline | Body_Copy | Priority_Order | Region-------------|----------|-----------|----------------|--------Speciality 1 | Headline | Body copy | 6 | 4Speciality 2 | Headline | Body copy | 4 | 4Speciality 3 | Headline | Body copy | 1 | 4Speciality 4 | Headline | Body copy | 5 | 4Speciality 5 | Headline | Body copy | 2 | 4Speciality 6 | Headline | Body copy | 3 | 4
Here is the SQL query I am using to pull the content for the engagement DE:
A.[Subscriber], A.[Region], A.[Engagement_Days] , A.[Engagement_SL], ROW_NUMBER() OVER (PARTITION BY A.[Contact:Id] ORDER BY A.[Engagement_Days] asc) AS [Priority_Order], B.[Region], B.[Specialty], B.[Region], B.[Headline], B.[Body_Copy], B.[Category]FROM [Content_DE] AS BLEFT JOIN [SL_Engagement_Days_by_Contact] AS A ON A.[Engagement_SL] = B.[Specialty] AND A.[Region] = B.[Region]WHERE B.[Category] IS NOT NULL
I am not able to pull in the remaining blocks that there is no engagement match for the engagement DE audience. For example, if a subscriber has engagement for 4 blocks, I am able to get the code to display the 4 blocks but the remaining two that match their region does not pull through. Is there a way for me to add all the remaining content rows that a subscriber should get?
thank you!