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

Change dataLayer Variable Name #42

Open
klcodanr opened this issue Nov 11, 2019 · 7 comments
Open

Change dataLayer Variable Name #42

klcodanr opened this issue Nov 11, 2019 · 7 comments
Labels
enhancement New feature, or improvement to an existing feature. pull request Has a pull request associated.
Milestone

Comments

@klcodanr
Copy link

klcodanr commented Nov 11, 2019

Expected Behaviour

I may want to change the name of the dataLayer variable. For example, if an implementor already has Google Tag Manager implemented, and they are looking to implement an Adobe Client Data Layer, they will have to deal with a naming conflict between the Adobe Client Data Layer and GTM's built-in DataLayer. We have a few choices to fix this:

  1. Rip & remove all GTM code
  2. Rename GTM's DataLayer, then rewrite the server-side GTM push code and implement the Adobe Client Data Layer
  3. Rename the Adobe Client Data Layer and initially keep the GTM code in place before sunsetting once the new tracking is fully implemented

To support option # 3, there would need to be some way to pass a new dataLayer name to the Adobe Client Data Layer.

Actual Behaviour

There appears to be no way to chage dataLayer variable name

Reproduce Scenario (including but not limited to)

N/A

Steps to Reproduce

N/A

Platform and Version

1.0.0.beta2

Sample Code that illustrates the problem

N/A

Logs taken while reproducing problem

N/A

@jckautzmann
Copy link
Contributor

jckautzmann commented Apr 29, 2020

@klcodanr Now that we introduced support for pushing a function into the data layer, the adobeDataLayer object can be renamed myDataLayer as follows:

window.adobeDataLayer = window.adobeDataLayer || [];
window.adobeDataLayer.push(function(dl) {
    window.myDataLayer = dl;
});

@Aaronius
Copy link

Aaronius commented May 3, 2020

@jckautzmann, that would only be useful if I don't need to push things onto window.myDataLayer until after the data layer library loads, correct?

A more flexible solution might be to allow the consumer to provide the name of the data layer on the script element itself. Here's an example, assuming you want to support multiple data layers:

<script>
  window.myDataLayer = [];
  window.myOtherDataLayer = [];
</script>
<script src="adobe-client-data-layer.min.js" async defer data-layers="myDataLayer,myOtherDataLayer"></script>

Then when the script loads, have the script pull the names of the data layers using document.currentScript.dataset.layers

@vladbailescu
Copy link
Member

@Aaronius , I would rather put that data-layers attribute on the script element where the global objects are defined:

<script data-layers="myDataLayer,myOtherDatalayer">
  window.myDataLayer = [];
  window.myOtherDataLayer = [];
</script>

Then we could pull the names using document.querySelectorAll('[data-layers]').

@jckautzmann
Copy link
Contributor

Also relates to #44

@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

By default the adobeDataLayer is created. The rename it, add the following HTML to your page head:

    <script data-adobe-client-data-layers="myDataLayer">
      window.myDataLayer = window.myDataLayer || [];
    </script>

For more details:
#44 (comment)

@jckautzmann jckautzmann self-assigned this May 12, 2020
@jckautzmann jckautzmann added in progress Work is underway on implementing this fix or enhancement. enhancement New feature, or improvement to an existing feature. and removed in progress Work is underway on implementing this fix or enhancement. labels May 12, 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
@shraddhanegi
Copy link

shraddhanegi commented Jun 18, 2020

how to include this nodemodule @adobe/adobe-client-data-layer/dist/adobe-client-data-layer.min.js into head.html of AEM site any documentation would help a lot, I wrote <script src="adobe-client-data-layer.min.js"></script> after installing package but it doesn't work even importing in publish.entry.js doesn't help it throw error e.function not defined when I do window.addDataLAyer.getState() something none of the helper function working

@jckautzmann
Copy link
Contributor

@shraddhanegi The integration of the Data Layer with AEM is explained at: https://github.com/adobe/aem-core-wcm-components/blob/master/DATA_LAYER_INTEGRATION.md

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

6 participants