1

I am trying to implement a custom unsubscribe page in Sitecore EXM. The setup is running on Sitecore 9.0.2.

While doing my part of the research found out this link - EXM Custom Unsubscribe

but it's unclear to me how the RedirectUrl.aspx is changed to support the custom page.

My requirement is to navigate to a custom page when the user clicks the Unsubscribe link in their email id, navigate them to a page where I have a Form with a field why they want to unsubscribe and a Submit Action attached to the Unsubscribe button.

My plan is to get the MessageId & Contact id from query string passed from the custom unsubscribe page and use them in IClientApiService to unsubscribe them from contact lists.

Appreciate any help. Thanks in advance.

-Dash

2 Answers 2

2

How RedirectUrl.aspx Page Works In General

The RedirectUrl.aspx page is a passthrough page for links coming out of messages generated by EXM. When this page is it on the Content Delivery server, it actually processes a pipeline called <redirectUrl> that will decrypt the query parameters coming out of the message. In these query parameters, include the URL to eventually go to, plus additional information like Contact ID, Message Id, and Contact Identifier.

Additionally, when dealing specifically with the Unsubscribe.aspx page, while the link will look like the RedirectUrl.aspx page out on the email, if the link is to the /sitecore%20modules/Web/EXM/Unsubscribe.aspx or /sitecore%20modules/Web/EXM/UnsubscribeFromAll.aspx, this will immediately process the Unsubscribe, remove the user from the associated list (as found in the Message via the Message ID). If the list can't be derived, then the contact is added to the Global Opt Out List. Last but not least, the user is then redirected to the Final Confirmation Page if one has been defined on the Manager Root.

enter image description here

How to Get it to work for your Requirement

It appears you have noticed that the query parameters you seek are available on the RedirectUrl.aspx request and passed through to the Unsubscribe.aspx page. In order to have a custom Unsubscribe page that makes use of those parameters, you will need to add your custom Unsubscribe page to the Carryover Fields in the <redirectUrl> pipeline.

enter image description here

As shown here, you'll want to add your custom unsubscribe page to the urlPattern of any query string field that you want to be carried over to your unsubscribe page.

This will then allow you to use the Client API as needed.

For information about Unsubscribe in general visit: https://sitecorehacker.com/2018/12/17/managing-the-unsubscribe-part-1

For information about the Client API: https://sitecorehacker.com/2018/12/21/managing-the-unsubscribe-part-5

2
  • Hi Pete, Thanks for the response. I made it work after sorting out few other stuff along with this. Found out our Unsub page was content manageable so had to modify that. One question here - Can the changes in config file you mentioned above achieved through a patch file?
    – Dash
    Commented Jul 19, 2019 at 2:24
  • It can, however, it's not as straightforward because of the fact the node you need has no real identification. <param desc="urlPattern"> doesn't lend well to targeting when there's 5 of them that are identical. So, unfortunately, you have to actually target the <carryoverField ... > node, use patch:delete to delete it, and then replace it with a copy, that includes the modifications to the UrlPattern you seek. Disclaimer: This method is how I know to do it. If someone else knows of a better way, I'm open to better advice. Commented Jul 19, 2019 at 3:40
1

The solution is as Pete mentioned. However, for the benefit novice Sitecore developers like me I'll post the end-to-end flow how I achieved this feature modification.

1.You have two ways to inject custom unsubscribe functionality:

  • Change the "CodeBehind" and "Inherits" attributes at "\sitecore modules\Web\EXM\Unsubscribe.aspx" to your own implemetation e.g.

    CodeBehind="CustomUnsubscribe.cs" Inherits="Feature.UnsubscribeNewsletterSubmitAction.Events.CustomUnsubscribe,Feature.UnsubscribeNewsletterSubmitAction"

  • Create your "CustomUnsubscribe.aspx" file, put in your hosted source code and refer in email campaign html/cshtml. e.g.

    href="/sitecore%20modules/Web/EXM/CustomUnsubscribe.aspx"

and add this file to the config file as mentioned by Pete. To create a patch config you may follow the below code(N.B. Path file isn't mandatory, you may make changes directly in EmailExperience.ContentDelivery.config file if you wish).

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
  <pipelines>
   <group groupName="exm.messageEvents">
    <pipelines>
      <redirectUrl>
        <processor type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.SetRedirectToUrl, Sitecore.EmailCampaign.Cd" resolve="true">
          <internalCarryoverFields hint="list:AddInternalCarryoverField">
            <patch:delete />
          </internalCarryoverFields>
        </processor>
      </redirectUrl>
     </pipelines>
    </group>
    </pipelines>
  </sitecore>
</configuration>

The above code deletes the "internalCarryoverFields" node.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
  <pipelines>
   <group groupName="exm.messageEvents">
    <pipelines>
      <redirectUrl>
        <processor type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.SetRedirectToUrl, Sitecore.EmailCampaign.Cd" resolve="true">
          <internalCarryoverFields hint="list:AddInternalCarryoverField">
          <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
              <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.MessageId']/@value" />
              <param desc="urlPattern">.*CustomUnsubscribe.aspx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
              <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.AnalyticsContactId']/@value" />
              <param desc="urlPattern">.*CustomUnsubscribe.aspx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
              <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.ContactIdentifierSource']/@value" />
              <param desc="urlPattern">.*CustomUnsubscribe.aspx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
              <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.ContactIdentifierIdentifier']/@value" />
              <param desc="urlPattern">.*CustomUnsubscribe.aspx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
                <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.Campaign']/@value" />
                <param desc="urlPattern">.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
                <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.TargetLanguage']/@value" />
                <param desc="urlPattern">.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
                <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.TestValueIndex']/@value" />
                <param desc="urlPattern">.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
            <carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
                <param desc="fieldKey" ref="settings/setting[@name='QueryStringKey.EmailHistoryEntryId']/@value" />
                <param desc="urlPattern">.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*</param>
            </carryoverField>
          </internalCarryoverFields>
        </processor>
        </redirectUrl>
     </pipelines>
    </group>
    </pipelines>
  </sitecore>
</configuration>

The above config code adds the "internalCarryoverFields" node with our custom page entry. Make sure you put the above changes in 2 different config files where node deletion is done first and then addition of custom page.

Post which I believe you will your custom logic to Unsubscribe the contact using ClientApiService.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.