November Happy Hour will be moved to Thursday December 5th.

Sergii Vorushylo
Aug 25, 2011
  4236
(0 votes)

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();
   5:  
   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:     }
  12:  
  13:     // Get conversion page reference
  14:     PageReference conversionReference;
  15:     if (!PageReference.TryParse(test.Conversion.Reference, out conversionReference))
  16:     {
  17:         return;
  18:     }
  19:  
  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()));
  29:  
  30:     // Save empty reference to cookie in order to avoid multiple conversions from single user
  31:     LpoContextHelper.Instance.SetToCookie(conversionReference, PageReference.EmptyReference, test.GetCookieExpirationDate());
  32:  
  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

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog