@using Kentico.Activities.Web.Mvc
@* Registers the script that allows custom activity logging *@
@Html.Kentico().ActivityLoggingAPI()
...
<script>
function trackSalesSearch() {
kxt('customactivity', {
type: 'SellingPropertySearch',
value: '', // Keep it blank for now, we will add some context later
title: 'Property search for sale'
});
}
// Add an event listener to track the activity after the page load
window.addEventListener('load', trackSalesSearch);
</script>
var activity = new ActivityInfo
{
ActivityCreated = DateTime.Now,
ActivityType = "SellingPropertySearch",
ActivitySiteID = siteId,
ActivityContactID = ContactManagementContext.CurrentContactID
};
activity.Insert();
using CMS.Activities;
private readonly ICustomActivityLogger customActivityLogger;
...
var salesPropertySearchActivityData = new CustomActivityData() {
ActivityTitle = "Property search for sale",
ActivityValue = ""
};
customActivityLogger.Log("SellingPropertySearch", salesPropertySearchActivityData);
public class SellingPropertySearchActivityInitializer : CustomActivityInitializerBase
{
private readonly string activityValue;
private readonly int activityItemId;
public SellingPropertySearchActivityInitializer(string activityValue = "", int activityItemId = 0)
{
this.activityValue = activityValue;
this.activityItemId = activityItemId;
}
public override void Initialize(IActivityInfo activity)
{
activity.ActivityTitle = "Property search for sale";
activity.ActivityValue = activityValue;
activity.ActivityItemID = activityItemId;
}
public override string ActivityType => "SellingPropertySearch";
var service = Service.Resolve<IActivityLogService>(); // or retrieve it from DI container
var activityInitializer = new SellingPropertySearchActivityInitializer("value");
service.Log(activityInitializer);
var propertySearchAttributes = new PropertySearchAttributesInfo()
{
PropertyType = "Flat",
Location = "London",
PriceFrom = 350000,
PriceTo = 500000,
BedroomsFrom = 2,
BedroomsTo = 3,
Status = "Available"
};
propertySearchAttributes.Insert();
var service = Service.Resolve<IActivityLogService>();
var activityInitializer = new SellingPropertySearchActivityInitializer("", propertySearchAttributes.PropertySearchAttributesID);
service.Log(activityInitializer);
SELECT *
FROM OM_Activity a
INNER JOIN Custom_PropertySearchAttributes psa
on a.ActivityItemID = psa.PropertySearchAttributesID
WHERE a.ActivityType = 'SellingPropertySearch'
[Serializable]
public class SalesSearch
{
public string PropertyType { get; set; }
public string Location { get; set; }
public int PriceFrom { get; set; }
public int PriceTo { get; set; }
public int BedroomsFrom { get; set; }
public int BedroomsTo { get; set; }
public string Status { get; set; }
}
public static string SerializeToXml<T>(T obj)
{
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = false
};
using (StringWriter stringWriter = new StringWriter())
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
{
var xs = new XmlSerializerNamespaces();
xs.Add("", "");
var serializer = new XmlSerializer(obj.GetType());
serializer.Serialize(xmlWriter, obj, xs);
return stringWriter.ToString();
}
}
var propertySearchAttributes = new SalesSearch
{
PropertyType = "Flat",
Location = "London",
PriceFrom = 350000,
PriceTo = 500000,
BedroomsFrom = 2,
BedroomsTo = 3,
Status = "Available"
};
var service = Service.Resolve<IActivityLogService>();
var activityInitializer = new SellingPropertySearchActivityInitializer(SerializeToXml(propertySearchAttributes));
service.Log(activityInitializer);
<SalesSearch>
<PropertyType>Flat</PropertyType>
<Location>London</Location>
<PriceFrom>350000</PriceFrom>
<PriceTo>500000</PriceTo>
<BedroomsFrom>2</BedroomsFrom>
<BedroomsTo>3</BedroomsTo>
<Status>Available</Status>
</SalesSearch>
@using Kentico.Activities.Web.Mvc
@* Registers the script that allows custom activity logging *@
@Html.Kentico().ActivityLoggingAPI()
@{
var propertySearchAttributes = new SalesSearch
{
PropertyType = "Flat",
Location = "London",
PriceFrom = 350000,
PriceTo = 500000,
BedroomsFrom = 2,
BedroomsTo = 3,
Status = "Available"
};
}
...
<script>
function trackSalesSearch() {
kxt('customactivity', {
type: 'SellingPropertySearch',
value: '@SerializeToXml(propertySearchAttributes)',
title: 'Property search for sale'
});
}
// Add an event listener to track the activity after the page load
window.addEventListener('load', trackSalesSearch);
</script>