Try our conversational search powered by Generative AI!

Sergii Vorushylo
Aug 25, 2011
  4114
(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
Run imgproxy container on Azure App Service with Front Door CDN

A simple way to host a imgproxy Docker container and use it to get AVIF and WEBP images.

Johan Kronberg | May 5, 2024 | Syndicated blog

Why C# Developers Should Embrace Node.js

Explore why C# developers should embrace Node.js especially with Optimizely's SaaS CMS on the horizon. Understand the shift towards agile web...

Andy Blyth | May 2, 2024 | Syndicated blog

Is Optimizely CMS PaaS the Preferred Choice?

As always, it depends. With it's comprehensive and proven support for complex business needs across various deployment scenarios, it fits very well...

Andy Blyth | May 2, 2024 | Syndicated blog

Adding market segment for Customized Commerce 14

Since v.14 of commerce, the old solution  for adding market segment to the url is not working anymore due to techinal changes of .NET Core. There i...

Oskar Zetterberg | May 2, 2024

Blazor components in Optimizely CMS admin/edit interface

Lab: Integrating Blazor Components into Various Aspects of Optimizely CMS admin/edit interface

Ove Lartelius | May 2, 2024 | Syndicated blog

Anonymous Tracking Across Devices with Optimizely ODP

An article by Lead Integration Developer, Daniel Copping In this article, I’ll describe how you can use the Optimizely Data Platform (ODP) to...

Daniel Copping | Apr 30, 2024 | Syndicated blog