2
votes

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.

2
Just to confirm does the link contain sc_item_id in the querystring? The link in an ECM email should auto generate the parameters in the querystring and you should have some reference back to the original email.Ian Graham
No. The link does NOT contain an sc_item_id parameter. The only values on the URL besides ec_contact_id are ec_message_id and _id.Dave

2 Answers

1
votes

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);
}
0
votes

When you create a new user in an email list, Sitecore creates a record in the xDB Mongo database. You should be able to get the email address from the users profile.

Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Entries[Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Preferred]

Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Entries["work_email"]