sitecoresitecore8sitecore-mvcsitecore-exm

Accessing Current Recipient in Sitecore 8 Email Experience Manager


How do you get the raw contact id from the ec_contact_id on the URL created by EXM?

We are using Sitecore's EXM to send emails containing links for surveys to recipients. When the recipient takes the survey we want to tie the response back to the recipient. Since EXM puts a unique Id, ec_contact_id, for the contact (encrypted) we want to use that to determine the recipient versus adding our own custom id.

We found this article, https://briancaos.wordpress.com/2015/04/27/sitecore-8-exm-get-the-email-recipient-from-a-sublayout/, and tried implementing it in the Sitecore controller that gets called when the recipient clicks on the link but the resulting recipient name comes back as empty. We don't have a "sc_item_id" value so we tried "_id" and "ec_message_id" in its place but neither value produced a valid contact Id or recipient name. We also tried looking in MongoDB with the decrypted contactId but couldn't find a match.


Solution

  • You could try somthing like this:

    //get value of the ec_contact_id parameter for current request
    string queryString = WebUtil.GetQueryString( Sitecore.Modules.EmailCampaign.GlobalSettings.AnalyticsContactIdQueryKey); 
    
    var shortID =  ShortID.TryParse(queryString, out shortID);
    
    System.Guid contactId;
    
    // where initializationVector is System.Guid of your email message item.
    using (var cryptoServiceProvider = new GuidCryptoServiceProvider(System.Text.Encoding.UTF8.GetBytes(GlobalSettings.PrivateKey), initializationVector.ToByteArray())) 
    {
           contactId = cryptoServiceProvider.Decrypt(shortID.Guid);
    }