Try our conversational search powered by Generative AI!

A/B Testing Addon and Content Versions

Vote:
 

Hello,

We are on Episerver.CMS 11.20.5 and attempting to use Episerver.Marketing.Test 2.6.6, but I've noticed some unexpected side effects.

We have a language bar which allows you to switch to the version of the page in other languages and have the following code to determine the languages to show:

var existingPages = page.ExistingLanguages
                                    .Select(l => contentLoader.Get<PageData>(page.ContentLink.ToReferenceWithoutVersion(), l))
                                    .Where(p => p.Status == VersionStatus.Published);

We then use this to create a language specific URL so we can link to the page in other languages. The problem is that if you have an A/B test running for a page, it seems to technically be considered "Published", and this code returns English versions of the page only. English is the version associated with the current test.

Does anyone have any recommendations for how to identify the ExistingLanguages that are actually published when you are currently conducting an A/B test? Please let me know if you need more information.

#253655
Edited, Apr 20, 2021 17:47
Vote:
 

Ran into the exact same problem. Did you ever find a solution? 

#266130
Edited, Nov 02, 2021 17:57
Vote:
 

Hi

The issue is caused because the code above uses contentloader and triggers a content loaded event which ab testing is listening for. This in turn may cause an invalid url to be returned if the content under test is not available for the requested language or there is no test for that language.

Rather than use contentLoader.Get I wrote some code that demonstrates how to get the language urls without triggering AB. Instead it uses the IContentVersionRepository. I suppled two methods, one that gets the url for a specific language given a content reference, and another that gets all the urls for a specific content reference. 

I tested this with an alloy app and it seems to work fine and generated proper Urls for each of the languages I had configured. This code was applied directly to the header.cshtml page in an alloy app for demonstartion purposes and produced the expected Urls.

Hope this helps! 

<div>
	@functions
	{
		/// <summary>
		/// Gets the URL for a specific language and page without triggering AB
		/// </summary>
		/// <param name="languageBranch">the language to get the link for</param>
		/// <param name="link">content reference to the page</param>
		/// <returns></returns>
		public string GetMenuUrl(string languageBranch, ContentReference link)
		{
			var urlString = "NONE"; //  String.Empty; 

			var versionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
			var publishedVersions = versionRepository.ListPublished(link);

			// Get the published version of the uri for the language specified. Note that it can be null if
			// there are no published versions.
			var contentVersion = publishedVersions.Where(x => x.LanguageBranch == languageBranch).FirstOrDefault();
			if (contentVersion != null)
			{
				urlString = UrlResolver.Current.GetUrl(link, languageBranch, new VirtualPathArguments { ForceCanonical = true });
			}

			return urlString;
		}

		/// <summary>
		/// Gets all the language Url's for the specified content reference
		/// </summary>
		/// <param name="link">content reference to the page</param>
		/// <returns>Tuple containing the language branch and the URL associated with it</returns>
		public IEnumerable<Tuple<string, string>> GetAllAvailableUrls(ContentReference link)
		{
			var urlTuples = new List<Tuple<string, string>>();

			var versionRepository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
			var publishedVersions = versionRepository.ListPublished(link);

			foreach (var contentVersion in publishedVersions)
			{

				var urlString = UrlResolver.Current.GetUrl(contentVersion.ContentLink, contentVersion.LanguageBranch, new VirtualPathArguments { ForceCanonical = true });

				urlTuples.Add(new Tuple<string, string>(contentVersion.LanguageBranch, urlString));
			}

			return urlTuples;
		}
	}

	<h4>For the current page, we get the URL for each of the specified languages</h4>
	@{
		var url = GetMenuUrl("en", Model.CurrentPage.ContentLink);
		<div><a href="@url" title="@url">en @url</a></div>
		url = GetMenuUrl("sv", Model.CurrentPage.ContentLink);
		<div><a href="@url" title="@url">sv @url</a></div>
		url = GetMenuUrl("de", Model.CurrentPage.ContentLink);
		<div><a href="@url" title="@url">de @url</a></div>
	}
	<br>
	<h4>For the current page, get all the URL's for each available language'</h4>
	@{
		var tuples = GetAllAvailableUrls(Model.CurrentPage.ContentLink);
		foreach (var t in tuples)
		{
			<div><a href="@t.Item2" title="@url">@t.Item1 @t.Item2</a></div>
		}
	}
</div>
#277436
Mar 30, 2022 14:55
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.