private IPublishedContent GetVariation(PublishedContentRequest request, Experiment experiment, int variationId) { AssignVariationToUser(request, experiment.Id, variationId); if (variationId == -1) { return(null); //user is excluded } var variation = experiment.Variations[variationId]; if (!variation.IsActive) { return(null); } var pageId = variation.VariedContent.Id; var helper = new UmbracoHelper(UmbracoContext.Current); var variationPage = helper.TypedContent(pageId); if (variationPage == null) { logger.Warn(GetType(), $"Cannot find the content (id {pageId}) for variation #{variationId} of {experiment.Id} experiment! " + $"This might occur on testing environments if you use live Google Analytics account and in such cases can be ignored. " + $"Alternatively the variation page might have been deleted or unpublished, check the experiment and make sure all variations have mathcing content."); } return(variationPage); }
private bool ShouldVisitorParticipate(Experiment experiment) { var coverage = experiment.GoogleExperiment.TrafficCoverage ?? 1; var r = random.NextDouble(); return(r <= coverage); }
private bool ShouldApplyVariation(Experiment experiment, int variationId) { if (variationId == -1) { return(false); //user is excluded } var variation = experiment.Variations[variationId]; if (!variation.IsActive) { return(false); } return(true); }
public override async Task <Experiment> ExecuteAsync() { var service = await GetAnalyticsService(); var googleExperimentRequest = service.Management.Experiments.Get(account, ExperimentId); var googleExperiment = await googleExperimentRequest.ExecuteAsync(); var settings = OurExperiment.ParseSettings(googleExperiment.Description); settings.SegmentationProviderKey = ProviderKey; settings.SegmentationValue = Value; googleExperiment.Description = OurExperiment.UpdateSettings(googleExperiment.Description, settings); var request = service.Management.Experiments.Patch(account, googleExperiment); return(await request.ExecuteAsync()); }
private int SelectVariation(Experiment experiment) { var shot = random.NextDouble(); var total = 0d; for (int i = 0; i < experiment.Variations.Count; i++) { var variation = experiment.Variations[i]; total += variation.GoogleVariation.Weight ?? 0; if (shot < total) { return(i); } } return(0); }