Sitecore OMS - achieving a goal on a form submissi

2020-07-26 13:52发布

问题:

I inherited a Sitecore solution that has a sublayout that contains a complex ASP.NET ascx form which handles both payments and integration with 3rd party web services.

This sublayout uses parameters templates to provide some level of control on the way the form looks like.

The .ascx control contains multiple views:

  • In the first view the user fills the form and click NEXT.
  • In the second view the user can review the entered data before clicking the SUBMIT button.
  • The third view is the thank you page of the form.

If I want to create a goal for the submission of this form, am I supposed to set the goal as "achieved" via API on submission of the form itself? Should I add, maybe, the name of the goal as one of the parameter templates so that the marketing editors will be able to change it, if needed?

Thanks

回答1:

You have several possibilities:

  1. Most forms have a confirmation page, when everything is submitted and approved. You can attach an event to this page through the normal user interface. There are no special code required for this and it is out of the box.

  2. As you say you can do it by code. This is fairly easy and should look something like this:

    public void RegisterEvent(){ if (!AnalyticsTracker.IsActive) return;

    AnalyticsTracker tracker = AnalyticsTracker.Current;

    if (tracker == null || tracker.CurrentPage == null) return;

    AnalyticsPageEvent pageEvent = new AnalyticsPageEvent() { Name = "TheNameOfYourEvent", Key = "TheKeyOfTheEvent", Text = "SomeText", Data = "Event data can contain all the entered information if you like", };

    tracker.CurrentPage.TriggerEvent(pageEvent); tracker.Submit(); }

Whether you hardcode the event or you make it variable depends on whether you need to change the event frequent.

The first option is the most simple, but if you also want to integrate to a CRM and store user input, you might want to go with option 2 as you can store the profile data as well.

Hope that helps!



回答2:

Yes, you can set the goal as achieved using the AnalyticsTracker.TriggerEvent method at the appropriate point in your form's workflow. Putting the name of the goal as a template parameter is a great idea. Even better, use a droplink and point the source at /sitecore/system/Marketing Center/Goals/.

EDIT

See the Analytics Configuration Reference on how to programmatically "Register an Analytics Page Event."



标签: sitecore