Search code examples
sitecoresitecore7.2

Programatically track a visit to an item with a profile card


We've just taken over a site that a client is wanting to add personalisation to using profile and pattern cards.

However the way the sites been built means that a visitor never actually goes to the url for the item that would have the profile card assigned to it. Instead there going to a single page and a value on the query string tells the page which items data should be loaded. Therefore the user is never tracked as visiting the item and the profile card has no influence on the profile for the user.

Is there a way to pragmatically trigger what would normally happen so that the users builds up the profile score for these pages?

The site is using Sitecore 7.2


Solution

  • After digging through the analytics dll I found that you can do this.

    Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("web");
    (new TrackingFieldProcessor()).Process(db.GetItem(new ID("395BDEF7-16CB-4C94-B9B6-A6EAC148401F")));
    

    This will cause the profile key values to be updated correctly, but the visitor histroy will still look like the visitor didn't look at the page. To change that you can do this.

    VisitorDataSet.PagesRow rawUrl = Tracker.CurrentVisit.GetOrCreateCurrentPage();
    rawUrl.Url = "new url value";
    rawUrl.UrlText = "new url value";