The first step in this journey will be to get this data into Mongo as the user visits your product detail pages.
First create a facet to hold the products your user is looking at.
using Sitecore.Analytics.Model.Framework;
namespace YourApp.Analytics.Interfaces.Entries
{
public interface IElementProductInfo : IElement, IValidatable
{
string ProductId { get; set; }
string Category { get; set; }
string SubCategory { get; set; }
}
}
Then you need to create a new container to hold the facets. Using IElementDictionary makes this a one to many facet in the contact record.
using Sitecore.Analytics.Model.Framework;
namespace YourApp.Analytics.Interfaces.Entries
{
public interface IProductInfos : IFacet, IElement, IValidatable
{
IElementDictionary<IElementProductInfo> Entries { get; }
}
}
Now you need to make a concrete serializable class of your ProductInfo class
namespace YourApp.Analytics.Models.Generated
{
[Serializable]
internal class ElementProductInfo : Element, IElementProductInfo, IElement, IValidatable
{
private const string productId = "productId";
private const string category = "category";
private const string subCategory = "subCategory";
public ElementCustomerLookup()
{
base.EnsureAttribute<string>(productId);
base.EnsureAttribute<string>(category);
base.EnsureAttribute<string>(subCategory);
}
public string ProductId
{
get { return base.GetAttribute<string>(productId); }
set { base.SetAttribute<string>(productId, value); }
}
public string Category
{
get { return base.GetAttribute<string>(category); }
set { base.SetAttribute<string>(category, value); }
}
public string SubCategory
{
get { return base.GetAttribute<string>(subCategory); }
set { base.SetAttribute<string>(subCategory, value); }
}
}
}
Now create a concrete class for your entities interface.
namespace YourApp.Analytics.Models.Generated
{
[Serializable]
internal class ProductInfos: Facet, IProductInfos, IFacet, IElement, IValidatable
{
private const string ENTRIES = "Entries";
public IElementDictionary<IElementProductInfo> Entries
{
get
{
return base.GetDictionary<IElementProductInfo>("Entries");
}
}
public ProductInfos()
{
base.EnsureDictionary<IElementProductInfo>("Entries");
}
}
}
Finially lets bring it all together in a config file. This will register your classes as facets and make them available for use in Mongo.
<sitecore>
<model>
<elements>
<element interface="YourApp.Analytics.Interfaces.Entries.IProductInfos, YourApp.Analytics" implementation="YourApp.Analytics.Models.Generated.ProductInfos, YourApp.Analytics" />
<element interface="YourApp.Analytics.Interfaces.Entries.IElementProductInfo, YourApp.Analytics" implementation="YourApp.Analytics.Models.Generated.ElementProductInfo, YourApp.Analytics" />
</elements>
<entities>
<contact>
<facets>
<facet name="ProductInformation" contract="YourApp.Analytics.Interfaces.Entries.IProductInfos, YourApp.Analytics" />
</facets>
</contact>
</entities>
</model>
</sitecore>
The last bit it getting the data in Mongo is to add it to a users tracker.
var productInformationFacet = Tracker.Current.Contact.GetFacet<IProductInfos>("ProductInformation");
if (!productInformationFacet.Entries.Contains("YourProductId"))
{
var customer = productInformationFacet.Entries.Create("YourProductId");
customer.ProductId = "YourProductId";
customer.Category = "YourCategory";
customer.SubCategory = "YourSubCategory";
}
Your next step will be to aggregate up your data with your own BI logic. probably filtering on other products with the same category within a certain time frame. You will want to add a Processor to the analytics indexer. You can find a good example of that here. How can I create a custom report in Experience Analytics?