Question

I know that it is possible to enroll users in an engagement plan from with Sitecore by adding them to a specific state in the plan when they visit a campaign URL, adding them when they submit a Web Forms for Marketers Form, and manually adding them in the Supervisor interface.

Additionally, I know that you can use the API to add a user as described here: http://briancaos.wordpress.com/2013/06/03/programming-for-sitecore-dms-engagement-plans/

However, that method requires a username.

I would like to enroll anonymous users in an engagement plan when they visit any page represented by a particular template in Sitecore (ie, page from the Product template). Is this possible using the API?

Was it helpful?

Solution 2

Per Sitecore support, this is not currently possible. However, I was able to achieve what I wanted by adding a jQuery AJAX call to the campaign URL to the sublayout used by the page type in question. Naturally this only works for clients with JS enabled, but for my purposes, that is not an issue.

<script type="text/javascript">$(function() { $.get('/?sc_camp=[campaignid]'); });</script>

Edited 2014-05-19

I found a way to do this via the Sitecore API. This is rough and needs to check for null values, exceptions, etc., but it does work:

string cookieVal = Request.Cookies["SC_ANALYTICS_GLOBAL_COOKIE"].Value;
List<Guid> guids = new List<Guid>() {
    new Guid(cookieVal)
};
Guid automationStateId = new Guid("{24963AE9-1C8C-4E18-8EEE-01BC249D1F1B}");
Guid automationId = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(automationStateId)).ParentID.ToGuid();
Sitecore.Analytics.Automation.Data.AutomationManager.Provider.CreateAutomationStatesFromBulk(guids, automationId, automationStateId);

OTHER TIPS

To expand on my above comment, and to supplement your own answer, here's a processor that you could add to the after the ItemResolver in the httpRequestBegin pipeline that would achieve the desired result. It is a very basic version that you could embellish as you see fit

class CampaignRedirect
{
    public void Process(HttpRequestArgs args)
    {
        var request = HttpContext.Current.Request;

        // must not already have the querystring in the URL         
        if(request.QueryString["sc_camp"] != null &&
            request.QueryString["sc_camp"] != "XXXXXXXX")
            return;

        // must have a context item
        if(Sitecore.Context.Item == null)
            return;

        var item = Sitecore.Context.Item;

        // must be the right template
        if(item.TemplateID.ToString() != "{XXXXXXXXX-XXXX-XXXXXX}")
            return;

        var basicUrl = LinkManager.GetItemUrl(item);

        var response = HttpContext.Current.Response;

        response.Redirect(basicUrl + "?sc_camp=XXXXXXX");
    }
}

If you're not familiar with adding processors, take a look here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top