Sergii Vorushylo
Aug 25, 2011
  4161
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024