Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capability to instantiate multiple data layers #44

Open
gabrielwalt opened this issue Apr 16, 2020 · 4 comments
Open

Capability to instantiate multiple data layers #44

gabrielwalt opened this issue Apr 16, 2020 · 4 comments
Labels
enhancement New feature, or improvement to an existing feature. pull request Has a pull request associated.
Milestone

Comments

@gabrielwalt
Copy link
Member

gabrielwalt commented Apr 16, 2020

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

@jckautzmann
Copy link
Contributor

See also other ideas in #42

@jckautzmann
Copy link
Contributor

jckautzmann commented May 8, 2020

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 jckautzmann added the in progress Work is underway on implementing this fix or enhancement. label May 12, 2020
@jckautzmann jckautzmann self-assigned this May 12, 2020
@jckautzmann jckautzmann added enhancement New feature, or improvement to an existing feature. and removed in progress Work is underway on implementing this fix or enhancement. labels May 18, 2020
@jckautzmann jckautzmann added this to the future milestone May 18, 2020
@jckautzmann jckautzmann removed their assignment May 18, 2020
@gabrielwalt gabrielwalt added the pull request Has a pull request associated. label May 20, 2020
@rajeevyadav2
Copy link

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

@gabrielwalt
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or improvement to an existing feature. pull request Has a pull request associated.
Projects
None yet
Development

No branches or pull requests

3 participants