Sample Register a page event
After you have created a page event, you also need to register the page event programmatically. The code for registering page events ensures that when the event is triggered by a contact, it is registered in the Sitecore Experience Database (xDB). However, when a page event is triggered it is not stored in the xDB straight away, instead it is stored in the active session. This means that it is only saved to the xDB when the session ends. If the contact is classified as a robot, then the session and the page event are not saved to the xDB.
There are two code samples that you can use to register page events programmatically:
-
Standard registration code - full code for registering page events.
-
Registration code that prevents duplicate page events.
Standard registration code
Standard registration code
This code sample enables you to register page events:
Registration code that prevents duplicate page events
Registration code that prevents duplicate page events
There are two alternate ways to write an If statement to check for duplicates, using different LINQ statements.
Using the All LINQ extension:
Using the Any LINQ extension:
If the page event has not already been registered then it can now be registered.
Full code sample to avoid duplicate page events: