Capability to instantiate multiple data layers
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
See also other ideas in https://github.com/adobe/adobe-client-data-layer/issues/42
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-layersdata attribute set with a list of data layer names, multiple data layers will be created. In the example below,myDataLayerandmyOtherDataLayerwill be created. - if the
data-adobe-client-data-layersdata attribute is not available or empty, theadobeDataLayerdata 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 @gabrielwalt When this feature will be available in release?
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.