This topic describes how to customize mailing templates when using the Optimizely connect for Watson Marketing (Silverpop) add-on.
How it works
Watson Marketing (Silverpop) provides the base class SilverpopMailingPageBase to create a mailing template, which contains all required properties. By inheriting it, you can add custom properties to construct a mailing template.
The following code samples apply to a web form on the Optimizely CMS "Alloy" sample site.
- Create the content type page as follows:
using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.DataAnnotations; using EPiServer.MarketingAutomationIntegration.Core; using EPiServer.MarketingAutomationIntegration.Silverpop.Enums; using EPiServer.MarketingAutomationIntegration.Silverpop.Implementation; using EPiServer.MarketingAutomationIntegration.Silverpop.UI.PageTypes; using System.ComponentModel.DataAnnotations; namespace EPiServer.Templates.Alloy.Models.Pages { [ContentType(GroupName = "Connect For Marketing Automation")] [ImageUrlAttribute("~/Static/gfx/SilverpopMailingPage_Preview.png")] public class MySilverpopMailingPage : SilverpopMailingPage { [BackingType(typeof(PropertyString))] [Display(GroupName = EPiServer.MarketingAutomationIntegration.Constants.MAIPageTypeTabs, Order = 40)] public virtual string MyCustomProperty { get; set; } } }
- Create the template file with the following markup:
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" CodeBehind="SilverpopMailingPageTemplate.aspx.cs" Inherits="EPiServer.Templates.Alloy.Views.Pages.SilverpopMailingPageTemplate" %> <!DOCTYPE html> <html lang="en"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width" /> <!-- For injecting script resource into Mailing template page at header --> <EPiServer:RequiredClientResources RenderingArea="Header" ID="RequiredResourcesHeader" runat="server" /> </head> <body> <EPiServer:Property runat="server" PropertyName="MyCustomProperty" /> <form runat="server"> <EPiServer:Property runat="server" PropertyName="HTMLBody" /> </form> <!-- For injecting script resource into Mailing template page at footer --> <EPiServer:RequiredClientResources RenderingArea="Footer" ID="RequiredResourcesFooter" runat="server" /> </body> </html>
In code behind it should look as follows:
using EPiServer.Framework.DataAnnotations; using EPiServer.Templates.Alloy.Models.Pages; namespace EPiServer.Templates.Alloy.Views.Pages { [TemplateDescriptor(Path = "~/Views/Pages/SilverpopMailingPageTemplate.aspx")] public partial class SilverpopMailingPageTemplate : TemplatePage<SilverpopMailingPage> { } }
- Compile and run your project.
Customizing opt-in/opt-out functionality
You can develop opt-in and opt-out functionality for the mailings with the Optimizely Connect for Marketing Automation add-on.
The following web forms page works with the Watson Marketing (Silverpop) provider API and shows how you can opt in, opt out, or just check the status for the current user for the marketing automation add-on.
using System;
using System.Collections.Generic;
using System.Web.UI;
using EPiServer.MarketingAutomationIntegration.Caching;
using EPiServer.MarketingAutomationIntegration.Core;
using EPiServer.MarketingAutomationIntegration.Services;
using EPiServer.MarketingAutomationIntegration.Silverpop.APIs.XMLResultModel;
using EPiServer.MarketingAutomationIntegration.Silverpop.Domain;
using EPiServer.MarketingAutomationIntegration.Silverpop.Implementation;
using EPiServer.MarketingAutomationIntegration.Silverpop.Services;
using EPiServer.ServiceLocation;
namespace Samples
{
public partial class OptInOptOutSamples : Page
{
private SilverpopProvider _provider = WorkingContext.Current.ActiveProvider as SilverpopProvider;
private ContactService _contactService = ServiceLocator.Current.GetInstance<IProfileService>() as ContactService;
private ICacheService _cacheService = ServiceLocator.Current.GetInstance<ICacheService>();
protected void OptOut_Click(object sender, EventArgs e)
{
// opt out current contact
var contact = _contactService.GetCurrentProfile() as Contact;
if (contact == null)
{
lblOptOutResult.Text = "Cannot get current visitor! You must create visitor first by submit a XForm to Silverpop!";
return;
}
// need to specify recipient id to opt out exactly 1 contact in non email key database
var response = _contactService.OptOutRecipient(contact.DatabaseId, contact.Id);
if (response.WasSuccessful)
{
lblOptOutResult.Text = "Opted out current visitor successfully!";
return;
}
lblOptOutResult.Text = "Failed to opt out current visitor, error: " + response.Fault.FaultString;
}
protected void OptIn_Click(object sender, EventArgs e)
{
var contact = _contactService.GetCurrentProfile() as Contact;
if (contact == null)
{
lblOptInResult.Text = "Cannot get current visitor! You must create visitor first by submit a XForm to Silverpop!";
return;
}
var response = _contactService.AddRecipientNonKeyed(
contact.DatabaseId,
contact.VisitorKey.Value.ToString(),
new List<Column>());
if (response.WasSuccessful)
{
lblOptInResult.Text = "Opted in current visitor successfully!";
return;
}
lblOptInResult.Text = "Failed to opt in current visitor, error: " + response.Fault.FaultString;
}
protected void Show_Status_Click(object sender, EventArgs e)
{
var contact = _contactService.GetCurrentProfile() as Contact;
if (contact == null)
{
lblStatusResult.Text = "Cannot get current visitor! You must create visitor first by submit a XForm to Silverpop!";
return;
}
var selectRecipientResponse = _contactService.SelectRecipientData(contact.Id, true, contact.DatabaseId);
if (string.IsNullOrEmpty(selectRecipientResponse.OptedOut))
{
lblStatusResult.Text = "Current visitor is opted in";
}
else
{
lblStatusResult.Text = string.Format("Current visitor is opted out at: {0}", selectRecipientResponse.OptedOut);
}
}
}
}
Related topic
Last updated: Mar 18, 2020