Get Variation Name

Get Variation Name

The getVariationName() method retrieves the allocated variation name for a given user for a Full Stack A/B Test experiment.

This API only provided the variation allocated for the user and does not trigger tracking events to PageSense. You can use this API when you simply need to know which variation a user should be assigned and does not want to fire an activation event.

Calling the Method

  1. // Get the variation allocated to the user for a Full Stack A/B Test
  2. $variationName = $pageSenseClient->getVariationName($experimentName, $userId, $userAttributes);
Method Parameters

Parameter

Type

Description

experimentName

string

The name of the experiment to retrieve the variation for.

userId

string

A unique identifier for the user.

userAttributes

array

(Optional) Associative array of user attributes used for audience targeting and segmentation.

 

Return Value  

  • Returns the name of the allocated variation if the user qualifies for the Full Stack A/B Test.

  • Returns NULL if the user does not meet the audience targeting criteria or falls outside the experiment’s traffic allocation.

Example Code

  1. use Zoho\PageSense\PageSenseClient;
  2. // Create the user attributes array
  3. $userAttributes = [
  4.     'Browser' => 'Chrome',
  5.     'Device' => 'Desktop',
  6.     'OS' => 'Windows 10'
  7. ];
  8. // Get the variation allocated to the user for the experiment
  9. $variationName = $pageSenseClient->getVariationName($experimentName, $userId, $userAttributes);
  10. // Handle variation-specific logic
  11. if ($variationName === 'Original') {
  12.     // CODE: Logic for 'Original' variation
  13. } elseif ($variationName === 'Variation 1') {
  14.     // CODE: Logic for 'Variation 1'
  15. } elseif ($variationName === 'Variation 2') {
  16.     // CODE: Logic for 'Variation 2'
  17. } elseif ($variationName === 'Variation 3') {
  18.     // CODE: Logic for 'Variation 3'
  19. } else {
  20.     // CODE: When user is not part of any variation}


How the API Works
  

When getVariationName() method is invoked, it follows a series of steps to determine which variation should be assigned to the user.

1. Audience Targeting  

The API first evaluates whether the user qualifies for the experiment based on audience targeting conditions defined in PageSense.

Targeting conditions typically include attributes like browser, device type, operating system, or any custom user data you pass in the user attributes.

  • If the user matches the targeting conditions → the process continues.

  • If the user does not match the targeting conditions → the variation will be returned as NULL.

2. User Storage Service  

User Storage Service stores the variation allocated to the users for a given experiment in the user provided storage layer such as Database, Redis Cache or File System. It ensures that the user is always assigned the same variation for a given A/B Test across different sessions and browsers.

  • If a stored variation already exists for the given user Id for the experiment, it is retrieved from the storage and returned.

If not, the SDK proceeds to assign a new variation via hashing algorithm.

3. Hashing with MurmurHash  

The user ID and the experiment key is combined to form a unique key and the API applies the MurmurHash algorithm to this unique key and generate a numeric value between 0 and 9999.

MurmurHash algorithm generates the same hash value for a given user ID and experiment key pair. This ensures the user is always assigned a same variation for the given experiment across different sessions or browsers.

The generated hash value is then used to determine which variation the user falls into based on the experiment’s total traffic distribution and the individual traffic allocated for each variation.

4. Variation Mapping  

Each variation is assigned a non-overlapping hash range proportional to its traffic allocation. Assume for a give FullStack experiment, the total traffic allocation is 80% and the experiment has four variations mapped and each variation is assigned a traffic split of 25 percent, then each variation will have the following hash value ranges.

Variation

Hash Value Range

Original

0 – 2000

Variation 1

2001 – 4000

Variation 2

4001 – 6000

Variation 3

6001 – 8000

  • If the user’s hash value falls within one of these ranges → that variation is returned.

  • If the user’s hash value falls outside all defined ranges → the user is not part of the experiment, and NULL will be returned.

5. Return Value Logic  

Scenario

Return

User qualifies and variation assigned

Variation name

User fails audience targeting conditions

NULL

User falls outside the traffic allocation

NULL


Using getVariationName() Without User Attributes  

The getVariationName() API can also be invoked without user attributes. Currently this type of API call can be used only for the experiments that target “All Visitors.” It cannot be used for experiments that have specific audience targeting conditions as all the users won't match the audience targeting conditions since the user attributes are not passed in this API call.

Calling the Method

  1. // Get the variation allocated to the user
  2. $variationName = $pageSenseClient->getVariationName($experimentName, $userId);

How It Works  

  • Only ExperimentName and User Id are required.

  • Audience targeting still runs, but since no user attributes are passed:
          The user will qualify only for the experiments that target “All Visitors.”
         User will not qualify for the experiments that have specific audience targeting conditions because no user attributes are available.

  • Once qualified, the API uses the MurmurHash-based bucketing to determine the variation assignment.

  • If the user’s hash value falls outside the experiment’s traffic allocation → returns NULL.

Best Practices  

  • Always use consistent, unique user IDs (e.g., Login ID, Email Address etc). Avoid using session IDs for the user IDs, as they change frequently resulting in different variation served for the user for different session.

  • Always handle NULL returns gracefully. Add a fallback implementation in case the variation is returned as NULL.

  • Use caching for variation assignments for frequent users to avoid repeated hash evaluations.

  • Use the same name for the keys in the User Attributes across your application to ensure consistency in audience targeting and report segmentation.

NotesUse getVariationName() API if you want only the variation to be rendered in your web pages; use activateExperiment() API when you also want to track an activation event.

We hope this documentation helps make the process easy for you. Please feel free to reach out to us anytime by dropping an email to support@zohopagesense.com if you need more explanation or have any questions.

      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsEnterpriseOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceAccessible Forms
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit

                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic Forms
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsFormstack alternativeEncrypted Forms

                              Wufoo alternativeSecure Forms

                              TypeformWCAG


                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now




                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media


                                                                  • Desk Community Learning Series


                                                                  • Digest


                                                                  • Functions


                                                                  • Meetups


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner


                                                                  • Word of the Day


                                                                  • Ask the Experts


                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now








                                                                                                                            • Related Articles

                                                                                                                            • Add a custom event goal to your variation

                                                                                                                              A custom event goal is a slightly more advanced method of tracking every single behavior of a visitor on the page you are testing. This includes watching a video, submitting a form, completing a payment, or any other event that could not be tracked ...
                                                                                                                            • Track Goal

                                                                                                                              The trackGoal() method is used to record goal conversions for Full Stack A/B Testing experiments in PageSense. It records the conversion events in PageSense only for the users who qualify for the experiment. This API can be invoked with or without ...
                                                                                                                            • Get Variation Name

                                                                                                                              The Get Variation Name API is used to return the name of a FullStack A/B Test experiment. It evaluates whether the user qualifies for the experiment and assigns a variation accordingly. Using getVariationName without user attributes Method string ...
                                                                                                                            • Get Variation Name

                                                                                                                              The getVariationName API is used to get the allocated variation for the user for the specified FullStack A/B Test experiment. Method: String variationName = pageSenseClient.getVariationName(experimentName, userId, userAttributes); Parameters: ...
                                                                                                                            • Make advanced changes to the variation using JS/CSS editor

                                                                                                                              Apart from making changes manually to the design and content on your variation page, you can also directly write your own custom Javascript and CSS code changes using the PageSense visual editor. This option will provide you the freedom to quickly ...
                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources