How to Change the dataLayer Variable Name in Convert Experiments?

If you're using Convert Experiments and need to change the default dataLayer variable name to which the experiment data will be appended, follow these steps. This is essential for situations where you are working with custom implementations of Google Analytics 4 (GA4) or Google Tag Manager (GTM).

Prerequisites

Before proceeding, ensure that the GA4 integration is enabled in your Convert Experiments setup. This is required for the dataLayer customization to work correctly.

Steps to Change the DataLayer Variable Name

For GA4

To customize the dataLayer variable name when using GA4, you'll need to append a custom parameter to your tracking script. Here’s how to do it:

  1. In your Global JavaScript (GlobalJS), add the following line:

    javascript
    Copy code
    window._conv_q.push({ what: 'setIntegrationVariable', params: { integration: 'google_analytics', customVariable: 'yourCustomDataLayerName' } });

     

    Replace 'yourCustomDataLayerName' with the desired name for your dataLayer.

  2. This ensures that the experiment data will be appended to the renamed dataLayer instead of the default one.

For GTM

If you're using Google Tag Manager (GTM), the process is slightly different:

  1. Modify the fourth argument of the init function in your GlobalJS:

    javascript
    Copy code
    window._conv_q.push({ what: 'setIntegrationVariable', params: { integration: 'googletagmanager', customVariable:'yourCustomDataLayerName' } });

     

    Replace 'yourCustomDataLayerName' with the new dataLayer variable name.

  2. Alternatively, for the legacy tracking code (non v1), you can use the following method in your GlobalJS:

    javascript
    Copy code
    convert.integration_setting('gtm', 'dlv', 'yourCustomDataLayerName');

     

    Again, replace 'yourCustomDataLayerName' with the desired name.

Summary

  • GA4 Integration: Required for custom dataLayer name support.
  • Custom GA4 dataLayer: Use window._conv_q.push in GlobalJS.
  • Custom GTM dataLayer: Modify the fourth argument in the init function or use convert.integration_setting for the legacy tracking code (non v1).

By following these steps, you can successfully change the default dataLayer name in your Convert Experiments setup, ensuring that your analytics data is sent to the correct variable.