3

When I am importing contacts (within a scheduled job, which is our of request) I want to check few business conditions and if contact matches the condition, I want to trigger a goal for the contact.

The goal will execute rule action on enrolling the contact in the engagement flow.

Is that possible and how to do that?

1 Answer 1

2

Goal registration heavily relies on the current session. I am not aware of a good way to properly register a goal outside of actual session, page, and request being available.

To enroll a contact into a specific state in an engagement plan, you can try using this API:

using Sitecore.Analytics.Automation;

// ...

bool success = AutomationContactManager.AddContact(
    contactId,
    automationStateId,
    new Dictionary<string, object>());

This method will return false in the following cases:

  • The contact with given ID does not exist;
  • The database is unavailable;
  • The contact is locked by another process;
  • The contact is already in the given state;
  • The given automation state does not exist;
  • An exception occurs (it will be logged).

To check if a contact is already enrolled in a certain plan, you can use the following code:

Contact contact = ...
var manager = AutomationStateManager.Create(contact);
bool isInPlan = manager.IsInEngagementPlan(planId);
5
  • What is supposed to go into customData dictionary? the new Dictionary<string, object>()? Commented Dec 6, 2016 at 11:29
  • You don't have to pass anything—that dictionary is for custom values. It's mainly used by EXM states, I believe. Commented Dec 6, 2016 at 11:30
  • I also need to check whether this contact is already in this engagement flow (not necessarily in given state). If it is I should not enroll. I can't find a static method in AutomationContactManager for that... Commented Dec 6, 2016 at 12:34
  • @VolodymyrHil I have updated my answer to include that information. Commented Dec 6, 2016 at 12:45
  • Thanks a lot, will try this and let you know the results.. Commented Dec 6, 2016 at 12:57

Your Answer

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

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