1

What is the best way to get the best matching pattern card of all of the contacts?

I can only get the best pattern card of current contact:

var interactionProfile = Tracker.Current.Interaction.Profiles["Car"];
if (interactionProfile != null)
{
    // load the details about the matching pattern
    if (interactionProfile.PatternId.HasValue)
    {
        Item matchingPattern = Sitecore.Context.Database.GetItem(interactionProfile.PatternId.ToString());
        if (matchingPattern != null)
        {
            //handle your patterns here    
        }
    }
}

Can somebody suggest to me the best approach to achieve this? I wonder to konw if sitecore has provided API to access contacts information. For example engagement value,outcomes,best pattern matchs and so on.If somebody know,Please tell me how to do it,Thank you.

2
  • What exactly do you mean by "best matching pattern card for all of the contacts" ? What is your business scenario? Patterns don't necessarily apply to all contacts. Some patterns will apply to one segment, another pattern will apply to another segment. It is very unlikely that all contacts will have same pattern associated.
    – lebeg
    Nov 10, 2017 at 12:01
  • @lebeg Yes,you are right.Different contacts have different pattern card. But now I would like to have a visiter list with every visiter's best pattern card (maybe it's pattern card list) whom I could send some special message to .
    – Gray
    Nov 13, 2017 at 1:34

3 Answers 3

1

Using Fiddler I found that the Experience Profile (which shows each pattern in each profile with a percentage match) calls this API route:

http://[hostname]/sitecore/api/ao/v1/contacts/[contactid]/intel/profile-pattern-matches/[profileid]/?&pageSize=10&pageNumber=1&sort=PatternGravityShare%20desc&visitId=[visitid]

contactid is obviously the ID of the contact
profileid is the ID of the profile you're after
visitId is the ID of the last visit you want to include in the call

That gives you back some JSON, similar to:

{  
   "<Sort>k__BackingField":[  
      {  
         "<Direction>k__BackingField":2,
         "<Field>k__BackingField":"PatternGravityShare"
      }
   ],
   "<Filter>k__BackingField":[  

   ],
   "<Messages>k__BackingField":[  

   ],
   "<PageSize>k__BackingField":10,
   "<PageNumber>k__BackingField":1,
   "<TotalResultCount>k__BackingField":2,
   "<Data>k__BackingField":{  
      "<Dataset>k__BackingField":{  
         "profile-pattern-matches":[  
            {  
               "ContactId":"23cf560d-77df-43e4-ac8c-36d34ef55ef7",
               "LatestVisitId":"1ed2718a-ff18-44aa-b8f2-2c2beb799a00",
               "ProfileId":"b000189d-de2f-473f-817f-7006254f047e",
               "PatternId":"8a1c3791-3f6c-4d17-bac7-56f041faf66c",
               "PatternDisplayName":"Gamer",
               "PatternGravityShare":0.84728744130282752
            },
            {  
               "ContactId":"23cf560d-77df-43e4-ac8c-36d34ef55ef7",
               "LatestVisitId":"1ed2718a-ff18-44aa-b8f2-2c2beb799a00",
               "ProfileId":"b000189d-de2f-473f-817f-7006254f047e",
               "PatternId":"05943b7f-795d-4954-ae8a-af039814d139",
               "PatternDisplayName":"Business person",
               "PatternGravityShare":0.15271255869717254
            }
         ]
      },
      "<Lookups>k__BackingField":{  
      }
   }
}

In this, you're probably most likely after the 'PatternGravityShare', where the highest number is the 'winning' pattern.

For your use case, you might have to loop through all profiles and find the pattern with the highest 'PatternGravityShare'.

2
  • Thank you for teaching me a solution. I have to say it's a magical way to track the sitecore call.
    – Gray
    Nov 15, 2017 at 1:58
  • 1
    http://[hostname]/sitecore/api/ao/v1/contacts/[contactID]/intel/best-pattern-matches?&pageSize=3&pageNumber=1 I found this is another request url that could get best pattern info
    – Gray
    Nov 15, 2017 at 3:15
0

I get the contacts data about best pattern card by visit mongodb directly. I haven't used mongodb before,so I have to spend lots of time to learn it.

version: Sitecore 8.2 rev. 160729 sitecore 8.2 used mongodb driver(MongoDB.Driver.dll and MongoDB.Bson.dll version 1.10.0.62)

It is very important to notice your version of MongoDB because there are many different method for different version .Maybe some of them aren't available.

 var client = new MongoClient("mongodb://localhost:27017");//database connectstring
 var database = client.GetServer().GetDatabase("analytics");//database name
 var collection = database.GetCollection("Contacts");//collection(It likes table name)

 //only retrieve three fields
 string[] fields = { "System.Value", "PatternId", "Identifiers.Identifier" };
 //get the data by search condiction
 var contactInfoDB = collection.Find(Query.EQ("Identifiers.Identifier", "oEWyxv6y7JEuHISt50hQCjrLGHrk")).SetFields(fields).ToJson();
 //eventually you can use these info in your method


 string pattern = ".*?\"System\"(?s).*?{(?s).*?\"Value\"(?s) +:(?s) +(\\d+) +}.*";
 var match = Regex.Matches(contactInfoDB, pattern);
 var engagementValue = match[0].Groups[1].Value;

 pattern = ".*\"PatternId\"(?s).*?CSUUID\\(\"(.*?)\"\\).*";
 match = Regex.Matches(contactInfoDB, pattern);
 var bestPatternID = match[0].Groups[1].Value;
3
  • 1
    This should not be posted as an answer but rather as an update of your question Nov 13, 2017 at 14:03
  • Agreed. Please update the question. Nov 13, 2017 at 14:10
  • If there is another way can resolve my question,I will edit .Or else, this is the only way I can find .
    – Gray
    Nov 14, 2017 at 0:06
0

I did the similar things before, hope my answer could help you. My business scenario is about sending email to all of the users who belong to a specific best pattern, I create a custom segmented condition for List Manger to create a segmented list and then send email to the users by EXM.

In fact, you could get the users by search. In my project, I use Lucene Search. Open the sitecore_analytics_index, the best pattern card IDs(one user could match several different pattern cards) are stored in user information. enter image description here

The above screenshot shows the user matches 2 pattern cards. In you project, you could search the users by the specific pattern IDs, in sitecore_analytics_index.

Below is the code

using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Linq;
using System;
using System.Linq;
using System.Web.UI.WebControls;

namespace AddNewContactsSample
{
    public partial class GetLuceneSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            var index = ContentSearchManager.GetIndex($"sitecore_analytics_index");

            var q = index.CreateSearchContext().GetQueryable<ContactDoc>();
            q = q.Where(c => c.PatternIds.Contains("{82625C9F-DD9E-40E0-9C3B-16DB8E0F781F}"));
            var result = q.GetResults();
            var contacts = result.Hits.Select(x => x.Document).ToList();

        }

        public class ContactDoc
        {
            [IndexField("contact.identifier")]
           public string IdentifyID { get; set; }

            [IndexField("contact.patternids")]
           public string PatternIds { get; set; }
        }
    }
}
1
  • Thank you for your help. This is a non-programming approach that I need to program.Anyway thank you.
    – Gray
    Nov 14, 2017 at 7:07

Your Answer

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

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