How can we help?

Message engagement stats filters

Overview

To help improve visibility into how your messages are performing, we have provided custom Smarty code you can add to your messages. Once the code is added to your messages, you can see performance for contacts across several levels of engagement.

How engagement is defined here

Engagement in this example is defined by the last time a contact opened or clicked a message from your account, including contacts who subscribed within the defined lookback time periods. We then categorize contacts into four broad groups: 

  • Recently engaged: Includes contacts who have opened or clicked an email or subscribed in the past 14 days.
  • Semi-recently engaged: Includes contacts who have opened or clicked an email or subscribed in the past 14-90 days. 
  • Not recently engaged: Includes contacts who have opened or clicked an email or subscribed in the past 90-365 days.  
  • Never engaged: Includes contacts who haven't engaged in the past 365 days or more.

In the example below, you can click on the tabs to view the HTML include code, the message Smarty tag, and the filtered stats results.

{*. Place this include in an HTML include and name it engagement_stats. *}
{* Version 1.4 (The Sparkpost Version) *}
{$engagementTrancheStats.debug = 0}
{* sets the current time as $data.now for future use *}
{$data.engagementGroup = 'Not Engaged'}
{$data.contactCreatedDaysAgo = 99999}
{$data.lastEngagementDays = 99999}
{$data.openedDaysInPast = 99999}
{$data.clickedDaysInPast = 99999}
{$data.now = $smarty.now}
{* pulling opens from the last 180 days *}
{$openEvents.eventName = 'open'}
{$openEvents.newerThan = '-180'|date_format:'%Y-%m-%dT%H:%M:%S+0000'}
{$openEvents.properties = []}
{$openEvents.limit = 1}
{$openEvents.sort = ['column'=>'ats','direction'=>'DESC']}
{$openEvents.data = $utils->getEventRecords($openEvents.eventName,$openEvents.newerThan,$openEvents.properties,$openEvents.limit,$openEvents.sort)}
{* pulling clicks from the last 180 days *}
{$clickEvents.eventName = 'click'}
{$clickEvents.newerThan = '-180'|date_format:'%Y-%m-%dT%H:%M:%S+0000'}
{$clickEvents.properties = []}
{$clickEvents.limit = 1}
{$clickEvents.sort = ['column'=>'ats','direction'=>'DESC']}
{$clickEvents.data = $utils->getEventRecords($clickEvents.eventName,$clickEvents.newerThan,$clickEvents.properties,$clickEvents.limit,$clickEvents.sort)}
{* Set engagement as unix timestamps *}
{* if there are clicks it set the most recent click as a variable $data.lastEngagementDays *}
{if $clickEvents.data|count > 0}
   {$data.clickedDaysInPast = (($data.now - ($clickEvents.data.0.ats|strtotime)) / 60 / 60 / 24)|round:0}
   {$data.lastEngagementDays = $data.clickedDaysInPast}
{/if}
{* if there are opens it determines in the open or click is most recent and then sets that as $data.lastEngagementDays *}
{if $openEvents.data|count > 0}
   {$data.openedDaysInPast = (($data.now - ($openEvents.data.0.ats|strtotime)) / 60 / 60 / 24)|round:0}
   {if $data.openedDaysInPast < $data.lastEngagementDays}
       {$data.lastEngagementDays = $data.openedDaysInPast}
   {else}
       {$data.lastEngagementDays = $data.openedDaysInPast}
   {/if}
{/if}
{* determines if the contact was created in the last 14 days and if so sets a engagementGroup *}
{$data.contactCreatedDaysAgo = (($data.now - ($contact.createdAt|strtotime)) / 60 / 60 / 24)|round:0}
{if $data.contactCreatedDaysAgo <= 14}
   {$data.engagementGroup = "New Recipients"}
{else}
   {* finding the engagement group by comparing the last engagement date to the engagement criteria *}
   {if $data.lastEngagementDays <= 14}
       {$data.engagementGroup = 'Recently Engaged'}
   {elseif $data.lastEngagementDays <= 90}
       {$data.engagementGroup = 'Semi-Recently Engaged'}
   {elseif $data.lastEngagementDays <= 180}
       {$data.engagementGroup = 'Not Recently Engaged'}
   {else}
       {$data.engagementGroup = 'Not Engaged'}
   {/if}
{/if}

{* adds engagement group as send tag for easy stats filtering *}
{$utils->addSendTag({$data.engagementGroup})}
{* debugging tool to confirm it is working correctly *}
{if $engagementTrancheStats.debug == 1}
 <h2>Debug $data</h2>
 {$utils->jsonPrettyPrint($data)}
 <h2>Debug $clickEvents</h2>
 {$utils->jsonPrettyPrint($clickEvents)}
 <h2>Debug $openEvents</h2>
 {$utils->jsonPrettyPrint($openEvents)}
 <h2>Debug $contact</h2>
 {$utils->jsonPrettyPrint($contact)}
{/if}
{include 'content:engagement_stats' scope='parent' assign='blackhole'}

<!-- Message HTML -->

HTML content include code

To keep the HTML in your message clutter-free, paste the necessary Smarty code into an HTML content include and then insert that content into the message using a short Smarty "include" tag.

In Cordial, navigate to Content > HTML Content, create a new content piece, title it "engagement_stats". Make sure the key matches the title exactly, then paste the following code:

{*. Place this include in an HTML include and name it engagement_stats. *}
{* Version 1.4 (The Sparkpost Version) *}
{$engagementTrancheStats.debug = 0}
{* sets the current time as $data.now for future use *}
{$data.engagementGroup = 'Not Engaged'}
{$data.contactCreatedDaysAgo = 99999}
{$data.lastEngagementDays = 99999}
{$data.openedDaysInPast = 99999}
{$data.clickedDaysInPast = 99999}
{$data.now = $smarty.now}
{* pulling opens from the last 60 days *}
{$openEvents.eventName = 'open'}
{$openEvents.newerThan = '-60'|date_format:'%Y-%m-%dT%H:%M:%S+0000'}
{$openEvents.properties = []}
{$openEvents.limit = 1}
{$openEvents.sort = ['column'=>'ats','direction'=>'DESC']}
{$openEvents.data = $utils->getEventRecords($openEvents.eventName,$openEvents.newerThan,$openEvents.properties,$openEvents.limit,$openEvents.sort)}
{* pulling clicks from the last 60 days *}
{$clickEvents.eventName = 'click'}
{$clickEvents.newerThan = '-60'|date_format:'%Y-%m-%dT%H:%M:%S+0000'}
{$clickEvents.properties = []}
{$clickEvents.limit = 1}
{$clickEvents.sort = ['column'=>'ats','direction'=>'DESC']}
{$clickEvents.data = $utils->getEventRecords($clickEvents.eventName,$clickEvents.newerThan,$clickEvents.properties,$clickEvents.limit,$clickEvents.sort)}
{* Set engagement as unix timestamps *}
{* if there are clicks it set the most recent click as a variable $data.lastEngagementDays *}
{if $clickEvents.data|count > 0}
   {$data.clickedDaysInPast = (($data.now - ($clickEvents.data.0.ats|strtotime)) / 60 / 60 / 24)|round:0}
   {$data.lastEngagementDays = $data.clickedDaysInPast}
{/if}
{* if there are opens it determines in the open or click is most recent and then sets that as $data.lastEngagementDays *}
{if $openEvents.data|count > 0}
   {$data.openedDaysInPast = (($data.now - ($openEvents.data.0.ats|strtotime)) / 60 / 60 / 24)|round:0}
   {if $data.openedDaysInPast < $data.lastEngagementDays}
       {$data.lastEngagementDays = $data.openedDaysInPast}
   {else}
       {$data.lastEngagementDays = $data.openedDaysInPast}
   {/if}
{/if}
{* determines if the contact was created in the last 14 days and if so sets a engagementGroup *}
{$data.contactCreatedDaysAgo = (($data.now - ($contact.createdAt|strtotime)) / 60 / 60 / 24)|round:0}
{if $data.contactCreatedDaysAgo <= 14}
   {$data.engagementGroup = "New Recipients"}
{else}
   {* finding the engagement group by comparing the last engagement date to the engagement criteria *}
   {if $data.lastEngagementDays <= 14}
       {$data.engagementGroup = 'Recently Engaged'}
   {elseif $data.lastEngagementDays <= 90}
       {$data.engagementGroup = 'Semi-Recently Engaged'}
   {elseif $data.lastEngagementDays <= 180}
       {$data.engagementGroup = 'Not Recently Engaged'}
   {else}
       {$data.engagementGroup = 'Not Engaged'}
   {/if}
{/if}

{* adds engagement group as send tag for easy stats filtering *}
{$utils->addSendTag({$data.engagementGroup})}
{* debugging tool to confirm it is working correctly *}
{if $engagementTrancheStats.debug == 1}
 <h2>Debug $data</h2>
 {$utils->jsonPrettyPrint($data)}
 <h2>Debug $clickEvents</h2>
 {$utils->jsonPrettyPrint($clickEvents)}
 <h2>Debug $openEvents</h2>
 {$utils->jsonPrettyPrint($openEvents)}
 <h2>Debug $contact</h2>
 {$utils->jsonPrettyPrint($contact)}
{/if}

Message code

After creating your HTML content include, create a new message (Messages > Create New Message) and paste the following Smarty tag at the top of your message content. This ensures that the HTML content is rendered at the time the message is sent.

Note: Your contacts will not see any of the included Smarty code responsible for tracking engagement stats.
{include 'content:engagement_stats' scope='parent' assign='blackhole'}

<!-- Message HTML -->
Note: The same Smarty tag can be used in Sculpt messages as long as it's included in the HTML code of your Sculpt template.

Stats Filters results

After your message has finished sending, you can view the results in the Stats Filters section of the message performance page. (Performance for batch, or Aggregates for automated messages.)

The stat filters we added will not be immediately visible. Click the Filter By Tag button at the bottom of the Stats Filters table to add the desired labels.

Note: Only those filters that have data associated with them will be available to select. Over time, the Smarty code will capture and return engagement data based on contacts' interaction with your message.

Once added, the tags will remain in the Stats Filters section of your message but can be removed by clicking the X button for each filter to the right of the Stats Filters table (scrolling the Stats Filters table to the right may be required, depending on your display settings).

Engagement tags after being added to the Stats Filters page:

Comments

0 comments

Please sign in to leave a comment.