0

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, PageViewEvents 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?

5
  • Yes, you should override 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? Commented Aug 2, 2022 at 7:57
  • @MahendraShekhawat the question has been updated with additional info. Commented Aug 2, 2022 at 14:39
  • could you please try adding resolve="true" in your custom processor config? Commented Aug 3, 2022 at 9:32
  • No luck. What might be the purpose of that? I see that it "allows the Sitecore Dependency Injection engine to resolve the type name to run". Source: briancaos.wordpress.com/2019/03/14/… Commented Aug 3, 2022 at 15:22
  • hmm, yes it enables DI resolution for the processor. Commented Aug 3, 2022 at 15:43

1 Answer 1

0

I have come to the conclusion that the best way to do this is how I outlined in my original question, which is to override the default ConvertPageDataToPageViewEvent pipeline. However, that approach has limitations and drawbacks.

A better approach would be to register a custom event which allows for any necessary customization. That approach is outlined in a related question/answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.