Views: 3454
Number of votes: 0
Average rating:

Custom conversions in CMO LPO test

Today I was asked if it is possible to customize the behavior of LPO test so that the conversions is counted when user submit a form. Of course one of the solutions could be a separate page where user is redirected after a form submit and we can use that page as a conversion page in LPO test. On the other hand there is a more flexible way. Below is a code snippet that need to be placed in page template and called from a submit button event handler (or from any other event):

   1: private void IncreaseLpoConversion()
   2: {
   3:     // Get reference to the current page (with WorkID)
   4:     PageReference originalReference = LpoContextHelper.Instance.GetCurrentReference();
   6:     //Get LPO test containing page with PageReference equal originalReference
   7:     LpoTestLight test = LpoHelper.Instance.GetTestByOriginal(originalReference.ToString());
   8:     if (!test.HasValues)
   9:     {
  10:         return;
  11:     }
  13:     // Get conversion page reference
  14:     PageReference conversionReference;
  15:     if (!PageReference.TryParse(test.Conversion.Reference, out conversionReference))
  16:     {
  17:         return;
  18:     }
  20:     // Find if we were on some variation page and did not gathered statistics yet.
  21:     // The cookie should be set by LPO module when user enters on Original or one of the Variation pages
  22:     PageReference variationReference = LpoContextHelper.Instance.GetFromCookie(conversionReference);
  23:     if (PageReference.IsNullOrEmpty(variationReference))
  24:     {
  25:         return;
  26:     }
  27:     //Increase statistics
  28:     CmoData.Instance.IncreaseConversionLpoPageViewAsync(test.GetPageIdByReference(variationReference.ToString()));
  30:     // Save empty reference to cookie in order to avoid multiple conversions from single user
  31:     LpoContextHelper.Instance.SetToCookie(conversionReference, PageReference.EmptyReference, test.GetCookieExpirationDate());
  33: }

In order to make this code compile you need to reference EPiServer.Cmo.Core.dll and EPiServer.Cmo.Cms.dll.

Since Conversion page is a mandatory in LPO test we need to set it to some page that is not visible to users otherwise visits on that page might be counted as a conversions. Note that depending on your needs, you can control if it is allowed to count multiple submits for the same user by changing “Multiple impressions and conversions” option in CMO Settings.

Aug 25, 2011

Please login to comment.