adobe-client-data-layer icon indicating copy to clipboard operation
adobe-client-data-layer copied to clipboard

Capability to instantiate multiple data layers

Open gabrielwalt opened this issue 5 years ago • 4 comments

It would be useful to be able to create different instances of the Data Layer that can be named as desired. The use-case is that customers might want to use the same Data Layer API to store other data that they don't want to mix with the main adobeDataLayer. For example, because this data has different privacy rules, and they can then better guarantee that this other data won't get sent to the same tracking services.

This requirement doesn't impact how we'd use the Data Layer in most cases, though. For example, in Core Components, which would always rely on the existence of a specific variable, like adobeDataLayer. But it means that the Data Layer API must not be a singleton, but should allow being instantiated multiple times. Is this possible already? For example: var myOtherData = new AdobeDataLayer();

Allowing to make it an object we can instantiate would also help for unit testing it, for example.

This has been documented here: https://github.com/adobe/adobe-client-data-layer/wiki/Adobe-Client-Data-Layer#new-instance

gabrielwalt avatar Apr 16 '20 06:04 gabrielwalt

See also other ideas in https://github.com/adobe/adobe-client-data-layer/issues/42

jckautzmann avatar May 06 '20 08:05 jckautzmann

A proof of concept is available at: https://github.com/adobe/adobe-client-data-layer/tree/feature/create-copy-reset

It works as follows:

  • if the page HTML contains the data-adobe-client-data-layers data attribute set with a list of data layer names, multiple data layers will be created. In the example below, myDataLayer and myOtherDataLayer will be created.
  • if the data-adobe-client-data-layers data attribute is not available or empty, the adobeDataLayer data layer will be created.
    <script data-adobe-client-data-layers="myDataLayer,myOtherDataLayer">
      window.adobeDataLayer = window.adobeDataLayer || [];
      window.myDataLayer = window.myDataLayer || [];
      window.myOtherDataLayer = window.myOtherDataLayer || [];
      window.myDataLayer.push({ "test": "hello myDataLayer" });
      window.myOtherDataLayer.push({ "test": "hello myOtherDataLayer" });
    </script>

You can also create a data layer instance programmatically once the data layer script is initialised:

  • to create an empty data layer:
myDataLayerFoo = AdobeClientDataLayer.create();
  • to create a data layer by copying an existing one:
myDataLayerBar = AdobeClientDataLayer.create(myDataLayer);

jckautzmann avatar May 08 '20 15:05 jckautzmann

@jckautzmann @gabrielwalt When this feature will be available in release?

rajeevyadav2 avatar Jun 27 '20 12:06 rajeevyadav2

Hi @rajeevyadav2, We currently don't plan to work on this in the next month, but we probably want it addressed within the next 4 months.

gabrielwalt avatar Jul 22 '20 15:07 gabrielwalt