0

Page Events (defined in /sitecore/system/settings/Analytics/Page Events) cann be triggered like this:

var pageEventDefinition = Sitecore.Analytics.Tracker.MarketingDefinitions.PageEvents[pageEventId];
Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterPageEvent(pageEventDefinition);

How can I trigger a Generic Event? (defined in /sitecore/system/Marketing Control Panel/Events)

enter image description here

There is no property for these on the Sitecore.Analytics.Tracker.MarketingDefinitions object.

  • Generic Events are being used by System as System event so I don't think we should touch it, do you have any specific requirement for this? – Mahendra Shekhawat Mar 9 at 10:38
  • What happens when you try to get a system event by id from Sitecore.Analytics.Tracker.MarketingDefinitions.PageEvents? – grg Mar 9 at 10:39
  • @grg Sitecore.Analytics.Tracker.MarketingDefinitions.PageEvents doesn't contain these genereic events. I've tried that already. – Mark Lowe Mar 13 at 10:26
1

You can go with Definition managers as well, these are used to get marketing activities including the events. below example is to get the get definition manager in a Sitecore context and after that, you can get the event with the event id -

 IDefinitionManager<IEventDefinition> eventDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<IEventDefinition>();
 Guid eventId = Guid.Parse("YourEventID");
 //below line will give you the latest active version
 IEventDefinition marketingEvent = eventDefinitionManager.Get(eventId, new CultureInfo("da"));
 //you need to convert the marketing event into IPageEventDefinition
 Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterPageEvent((IPageEventDefinition)marketingEvent);

If you will see the inheritance of the Page Event items it is inheriting the Event template which is the same template use to create Generic events and in the RegisterPageEvent code its ultimately converting the IPageEventDefinition into IEventDefinition and calling a protected Register method.

| improve this answer | |
1

I would tend to agree with the comment above that system events should not be used by custom implementations, but if you really need that, you can create PageEventDefinition manually and register the event:

    Item pageViewItem = Sitecore.Context.Database.GetItem(new ID("{9326CB1E-CEC8-48F2-9A3E-91C7DBB2166C}"));
    PageEventDefinition pageViewEvent = new PageEventDefinition(pageViewItem.ID.Guid, pageViewItem.Name, Sitecore.Context.Culture, pageViewItem.Name, pageViewItem.Statistics.Created, pageViewItem.Statistics.CreatedBy);
    Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterPageEvent(pageViewEvent);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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