I'm wanting to do simple A/B testing for my website and curious how I can leverage the basic features of google analtyics to do this.

I found a very close question that already asks what I want, but I'm unsure about how I might go about "tagging" a user session, as the answer suggested. Events don't seem correct because I want a way to segment traffic based on group A and group B to see how they interact with the website, apart from one single feature or landing page.

Any suggestions are appreciated I'm getting lost in the documentation trying to figure this out.

1 Answer 1


I'll suggest you use Google Optimize for the test A/B. It's free and you can link it to Google Analytics easily.

If you want to make an experiment for the whole site and 'tag the user session', you could use the clientId (generated and used by Analytics) or userId (you must set and send your own userIds with your Analytics hits).

enter image description here

For example, you could retrieve the default clientId and therefore link the experiment to each user.

ga('create', 'UA-XXXXX-Y', 'auto', 'tracker');

ga(function(tracker) {
      var clientId = tracker.get('clientId');
      if (clientId == [condition]) {
        [experiment 1]
        [experiment 2]
  • Client ID was perfect, but what I did was use the client ID to choose "A" or "B" (via modulo 2 on the last digit). Your answer implies I'm running tests for each individual user but the idea was basically there, so thanks for pointing me in the right direction!
    – jamil
    Commented Oct 2, 2018 at 21:57
  • Glad to hear that, Jamil and thanks for letting me know. Regards.
    – Emirodgar
    Commented Oct 3, 2018 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.