We're tracking the internal search keywords via analytics PageEventData
api.
We're looking to get the data of these tracked search keywords.
Is there any analytics api to get these tracked search keywords?
To retrieve tracked search keywords from the Sitecore analytics database, you need to use xConnect
, which is the API for interacting with Sitecore's Experience Database (xDB)
. Through xConnect
, you can access analytics data, including search keywords.
Here's how you might implement these steps:
using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Collection.Model;
public class SearchKeywordTracker
{
public void GetTrackedSearchKeywords()
{
using (var client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
var query = client.Interactions.Where(x => x.Events.OfType<SearchEvent>().Any());
var interactions = query.GetBatchEnumerator();
while (interactions.MoveNext())
{
foreach (var interaction in interactions.Current)
{
foreach (var _event in interaction.Events.OfType<SearchEvent>())
{
var searchKeyword = _event.Keywords;
// Process search keyword
}
}
}
}
}
}
Hope this helps!!