Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Sergii Vorushylo
Aug 25, 2011
  4106
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog