Question: I am adding users to an engagement plan programmaticaly, using the following code:

```
VisitorManager.AddVisitor("salesforce\\fred.smith","{67F395B9-2C29-4B73-9382-69E0FCB6A546}");

```

This works fine, but I also need to store a custom value against the visit. Any ideas on how to do this?

I can't set `vistor.CurrentVisit.Profiles` as there is no setter available and there is no method available to add to it.

I am able to add tags with the following code

```
vistor.Tags.Add("opportunityId", "006M0000004xnLh");

```

However, when I try to retrieve them from within a custom automation action, the values returned are null. I guess because it was set programmaticaly and is being retrieved from a different session? The code I used to retrieve the tags is: 

```
var opportunityTagRow = visitorTags.Find("opportunityId");

```

and also:

```
var allOpportunityRows = visitorTags.GetAll("opportunityId");

```

Any ideas on how best to persist data for a visit?

Answer: 
I think you're confusing the concepts of "visitors" and "users" in Sitecore. In the Sitecore DMS a "Visitor" is essentially a cookie on a machine which maps to an entry in the Visitors table of the analytics database. A named User is someone who is logged into Sitecore and is stored in the .NET membership table in the core database. When you add a tag to a visitor this adds an entry to the VisitorTags table which is basically just a name-value pair which is mapped to the visitor entry in the Visitors table. In your case "salesforce\fred.smith" is not a Visitor but a User. You can retrieve the current visitor using Sitecore.Analytics.Tracker.Visitor or you can retrieve a different visitor by ID using the VisitorFactory. If alternatively you do want to persist data against a user, you can use the Users profile, which is again different to DMS and visitor profiles. You will find the relevant classes for Sitecore users under Sitecore.Security.

Edit: I would do what you want in the following way:

```
//Enroll user in plan
VisitorManager.AddVisitor("salesforce\\fred.smith", new ID("{67F395B9-2C29-4B73-9382-69E0FCB6A546}"));
//Add data to USER profile not visitor
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName("salesforce\\fred.smith", true);
user.Profile["opportunityId"] = "006M0000004xnLh";

//Get user from automation action parameter and get data from profile 
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(automationStatesRow.UserName, true);
string data = user.Profile["opportunityId"];

```
All visit data is stored in the Sitecore Analytics databases - See the visitor tags table. A visitor tag has an VisitorId that can be used to lookup the visitor. You have two options to get this data (along with another other Analytics data) - use the Sitecore Analytics API (recommended) or to retrieve the data you want by constructing custom sql calls (can get messy). Here's how I done something similar in an engagement action using the analytics API:

```
 public override AutomationActionResult Execute(VisitorDataSet.AutomationStatesRow automationStatesRow, Item action, bool isBackgroundThread)
 {
        Visitor visitor = VisitorFactory.GetVisitor();
        string tagValue = visitor.Tags["myTag"]
        //Do stuff
}

```