I have a case where I need page view events to store full URLs in the Url
property instead of just the paths.
For example, if I explore the Interactions
table, inside the Events
column, PageViewEvent
s have the following data:
{"@odata.type":"#Sitecore.XConnect.Collection.Model.PageViewEvent","CustomValues":[],"DefinitionId":"9326cb1e-cec8-48f2-9a3e-91c7dbb2166c","ItemId":"xxxxxxx","Id":"xxxxxxx","Timestamp":"2022-07-08T20:23:06.1411643Z","ItemLanguage":"en","ItemVersion":1,"Url":"/-/media/project/client/image.jpg","SitecoreRenderingDevice":{"Id":"fe5d7fdf-89c0-4d99-9aa3-b5fbd009c9f3","Name":"Default"}}
However, I would like the full URL to be stored in the Url prop; not just the path.
My analysis so far has shown that the Sitecore.XConnect.Collection.Model.PageViewEvent
class has a public string Url { get; set; }
property. My assumption is that the best practice would be to trigger the page view event manually and/or create a custom page view event model, and populate the Url
property with the value that I want. However, I don't want duplicate page view events (1 custom and 1 default).
Otherwise, it seems I would have to override the default behavior in Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectEventPipeline.ConvertPageDataToPageViewEvent
. As an example:
private PageViewEvent CreatePageViewEvent(PageData pageData)
{
// Note that there is so access to Sitecore context here
PageViewEvent pageViewEvent = new PageViewEvent(pageData.DateTime, pageData.Item.Id, pageData.Item.Version, pageData.Item.Language);
pageViewEvent.Duration = TimeSpan.FromMilliseconds((double)pageData.Duration);
// Populate the full URL here instead, or in PageData before we even get here
pageViewEvent.Url = pageData.Url.ToString();
// Or, create a new entry in CustomValues (though Sitecore says not to do this)
pageViewEvent.CustomValues.Add("FullUrl", "https://www.site.com/-/media/project/client/image.jpg");
...
}
As well as the associated config:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<convertToXConnectEvent>
<processor type="Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectEventPipeline.ConvertPageDataToPageViewEvent, Sitecore.Analytics.XConnect">
<patch:attribute name="type" value="Client.Foundation.DataExchange.Pipelines.ConvertToXConnectEventPipeline.ConvertPageDataToPageViewEvent, Client.Foundation.DataExchange" />
</processor>
</convertToXConnectEvent>
</pipelines>
</sitecore>
</configuration>
The above code does work, however, it modifies all page view events going forward which may not always be applicable. What approach would you recommend?
Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectEventPipeline.ConvertPageDataToPageViewEvent
for this, but it will not modify any exiting interactions, but will work for all new interactions. Could you please share your code and config changes here?resolve="true"
in your custom processor config?