When does is it written to xDB
Like the other answers said, it is written when the session closes. The time it takes to be written is in the web.config, in the session config. In the xml below, it is the timeout
. This number is in minutes.
<sessionState mode="InProc" cookieless="false" timeout="20" sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager">
So you do not have to wait, you can create a page or controller that will close the session for you. Just run this code and it will cause the xDB data to be written right away.
Session.Abandon();
Where is it written
The goal is written to the [xdb_collection].[Interactions] table in your shard databases.
If you query the table you can see the interactions, you can see the goals.
SELECT *
FROM [Xdb.Collection.Shard0].[xdb_collection].[Interactions]
Looking at the JSON in that field, the JSON will look like this.
[
{
"@odata.type":"#Sitecore.XConnect.Goal",
"CustomValues":[
],
"DefinitionId":"82c4c49c-b6b2-4b02-8e2f-fbcba9f92fe4",
"EngagementValue":60,
"Id":"335c92ce-5e36-4b13-9472-4940ad66e75f",
"Timestamp":"2019-05-07T23:53:34.4268677Z"
}
]
Is your test user anonymous?
By default Sitecore does not track anonymous users. And if your test user is anonymous, you are not going to see them in Experience Profile to see the goal. See here for turning it on.
Toot my own horn
I wrote a little tool that shows you in JSON what goals you have triggered in your current session and past sessions. You can find a 9.0.1 release. That should work with your 9.0.2 instance. When you trigger a goal in your session, you can just use an API to see what you triggered. It looks like this.
{
"GoalsList":[
{
"EngagementValue":5,
"Title":"2nd Visit",
"Date":"2019-04-23T01:13:43.8962374Z",
"IsCurrentVisit":false,
"Data":null
},
],
"PastGoals":[
{
"EngagementValue":5,
"Title":"3rd Visit",
"Date":"2019-04-23T01:45:01.34653Z",
"IsCurrentVisit":false,
"Data":null
},
{
"EngagementValue":5,
"Title":"2nd Visit",
"Date":"2019-05-14T03:43:12.6848242Z",
"IsCurrentVisit":false,
"Data":null
},
{
"EngagementValue":5,
"Title":"2nd Visit",
"Date":"2019-05-21T21:41:56.6825674Z",
"IsCurrentVisit":false,
"Data":null
}
]
}
The code to get the current is this. You can see the code here.
public IEnumerable<PageEvent> GetCurrentGoals()
{
var conversions = (from page in Tracker.Current.Interaction.GetPages()
from pageEventData in page.PageEvents
where pageEventData.IsGoal
select pageEventData).ToList();
foreach (var cachedGoal in conversions)
{
var goal = GetGoalDefinition(cachedGoal.ItemId);
yield return new PageEvent
{
Title = goal?.Name ?? "(Unknown)",
Date = cachedGoal.DateTime,
EngagementValue = goal?.EngagementValuePoints ?? 0,
IsCurrentVisit = false,
Data = cachedGoal.Data
};
}
}
SELECT COUNT(*) FROM [xdb_processing_pools].[InteractionLiveProcessingPool]