A/B Testing PlugIn ignores Tag Manager configuration regarding Cookie Domain

We are currently experiencing an issue with the use of Tag Manager and A/B Testing.

Here’s the situation:

The page is accessible at: www.ourdomain.abc
Our tracker is only accessible at: tracker.ourdomain.abc

On the page, we exclusively load the container_abc123.js from Tag Manager. During the page view, a Matomo configuration is loaded, which makes the following important settings:

Domains: *.outdomain.abc
Cookie Domain: .ourdomain.abc
Bundle Tracker: True
Register as Default Tracker: True

We have integrated the following additional code on a page:

<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['AbTesting::create', {
      name: '125',
      percentage: 100,
      includedTargets: [{"attribute":"url","inverted":"0","type":"equals_simple","value":"https:\/\/www.ourdomain.abc\/test-a.html"}],
      excludedTargets: [],
      startDateTime: '2023/07/14 00:00:00 UTC',
      endDateTime: '2023/09/14 23:59:59 UTC',
      variations: [
          {
              name: 'original',
              activate: function (event) {
                  // usually nothing needs to be done here
              }
          },
          {
              name: 'SiteB',
              activate: function(event) {
                  event.redirect('https://www.ourdomain.abc/test-b.html');
              }
          }            
      ]
  }]);
</script>

Now, the following occurs:

If the page is visited and the A/B test chooses the original, a tracking request is generated (e.g., https://tracker.ourdomain.abc/matomo.php?e_c=abtesting&e_a=125&e_n=original&…). Here, the following cookie is created, which contains a new VisitorID:
_pk_id.17.xyz // Domain: www.ourdomain.com // SameSite: Lax

(Note the difference in Tracking URL and Cookie Domain.)

Subsequently, the Tag Manager Tags generate additional tracking requests. These Requests naturally ignores the cookie from www.ourdomain.com and therefore create a new cookie with a new VisitorID:
_pk_id.17.xyz // Domain: .ourdomain.com // SameSite: Lax

This behavior now leads to a “empty visitor” being recorded with 0 actions. This visitor only has the information that they are participating in an A/B test. The second visitor (the actual visitor) generated by the Tag Manager now has all the other information of the real visitor but is not counted in the A/B test statistics.

If we add the cookie information to the A/B test snippet, we achieve the desired behavior:

_paq.push(["setDomains", [".ourdomain.abc"]]);
_paq.push(['setCookieDomain', '.ourdomain.abc']);

Loading the matomo.js synchronously beforehand and explicitly configuring the JavaScript tracker is not an option for us. Furthermore, we followed the recommendation of the A/B Testing Plugin and did not add the code as Custom HTML in the TM Container.

We assumed the following:

  • DOM Ready or Pageview event initializes the tracker with the TM option: “Initialize Only. Don’t track anything.”
  • Due to “Register as Default Tracker,” it is available to all plugins or further tracking requests.
  • Tracking events from plugins wait until the tracker is initialized and then use the full configuration.

Are we doing something wrong? Or is the implementation not intended in this way?

Hi @OlliWu ,

We have a bug report created for this, will post, once an update is provided.

1 Like

Hi @OlliWu ,

Have you by any chance added the cookie domain in the tag manager site variable in the below setting

Yes, of course. Thats exactly our Issue. As I said, It seems like this setting has no effect on the tracking used by A/B Testing.

Tag Manager Settings:

Hi @OlliWu ,

We have tested this and we could not reproduce the issue. We may need more details. Could you please get in touch with our support team at support@matomo.org and post the URL of this forum thread.