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

Add support for Google data layer #2613

Closed
wants to merge 3 commits into from
Closed

Add support for Google data layer #2613

wants to merge 3 commits into from

Conversation

brobatr
Copy link
Contributor

@brobatr brobatr commented Nov 6, 2023

Q                       A
Fixed Issues? None
Patch: Bug Fix? None
Minor: New Feature? Yes
Major: Breaking Change? No
Tests Added + Pass? Yes
Documentation Provided Yes
Any Dependency Changes? Yes, data layer read me
License Apache License, Version 2.0

The PR adds code to:

Make the name of the data layer configurable
Option to exclude ACDL but keep the other logic
Option to push to a datalayer using the gtag() function instead of push()
Modified unit tests

Please see the updated documentation in DATA_LAYER_INTEGRATION.md

Copy link

sonarcloud bot commented Nov 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@vladbailescu vladbailescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build is failing due to baseline check.
Also, to keep it simple, I would only add one extra property in the config/model to differentiate between ACDL and GTAG.

* {@code true} if the data layer client library should be included.
* @since om.adobe.cq.wcm.core.components.models 12.24.0
*/
default String getDataLayerName() { return DATALAYER_OBJECT_NAME_ADOBE; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require a package minor version bump

* {@code true} if ACDL library should be used.
* @since om.adobe.cq.wcm.core.components.models 12.24.0
*/
default boolean isDataLayerSkipAcdlInclude() { return false; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have isDataLayerClientlibIncluded that serves the same purpose (to control if the ACDL scripts should be included).

Copy link
Contributor Author

@brobatr brobatr Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @vladbailescu

unfortunately isDataLayerClienlibIncluded removes the datalayer.js file not just the ACDL. This may be a bug: when the flag is set to true there is an odd state - some component datalayer interaction happens as before (accordian, text etc), but the components that are caught in a loop in datalayer.js are no longer pushed to the datalayer. In short we get a semi-enabled state.

This is the reason (clienlib.config.js):

assets: {
js: [
"src/scripts/datalayer/v1/polyfill.js",
"node_modules/@adobe/adobe-client-data-layer/dist/adobe-client-data-layer.min.js",
"src/scripts/datalayer/v1/datalayer.js"
]
}

For the GDL I need to keep datalayer.js. This has led to the ugly approach of "remove DL clientlib and include part of it again"

Perhaps it would be better to change the existing functionality so that only the ACDL code is removed by isDataLayerClientlibIncluded? That would allow me to make the whole thing cleaner, and seems more intuitive.

* @private
* @param {HTMLElement} item The item to annotate as expanded
*/
* Annotates the item and its internals with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to reformat these

@@ -26,5 +26,12 @@
<sly data-sly-test="${clientLibCategoriesJsHead}" data-sly-call="${clientlib.js @ categories=clientLibCategoriesJsHead, async=page.isClientlibsAsync}"></sly>
<sly data-sly-test="${clientLibCategories}" data-sly-call="${clientlib.css @ categories=clientLibCategories}"></sly>
<link data-sly-test="${staticDesignPath}" href="${staticDesignPath}" rel="stylesheet" type="text/css" />
<sly data-sly-test="${page.data && page.dataLayerClientlibIncluded}" data-sly-call="${clientlib.js @ categories='core.wcm.components.commons.datalayer.v1', async=true}"></sly>
<sly data-sly-test="${!page.dataLayerSkipAcdlInclude}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have isDataLayerClientlibIncluded that serves the same purpose (to control if the ACDL scripts should be included).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see Page.java explanation above

* @return the type of push function (push() or gtag()) of the datalayer
* Defaults to push.
*/
@Property(label = "Use gtag function to push data")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to know that the name of the datalayer is gtag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the datalayer can be called anything or normally dataLayer, regardless of whether GA (gtag) or GTM is used.

* Defaults to false.
*/
@Property(label = "ACDL library not included")
boolean skipAcdlInclude() default false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have skipClientlibInclude that serves the same purpose (to control if the ACDL scripts should be included).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see reply to Paga.java above

@brobatr
Copy link
Contributor Author

brobatr commented Nov 14, 2023

Build is failing due to baseline check. Also, to keep it simple, I would only add one extra property in the config/model to differentiate between ACDL and GTAG.

This is rooted in the same issue as described in Page.java

there are four states now, assuming data layer is enabled:

ACDL + datalayer.js included - skipClientlibInclude = false
(possibly a bug) ACDL + datalayer.js not included - skipClientlibInclude = true
datalayer.js included, push using push() (GTM) - skipClientlibInclude = false, skipAcdlInclude() = true, usegtag=false
datalayer.js included, push using gtag() (GA) - skipClientlibInclude = false, skipAcdlInclude() = true, usegtag=true

what would be good and would remove a boolean option, if the second state is actually a bug is:

enabled: datalayer.js included

ACDL included - skipClientlibInclude = false
ACDL not included - skipClientlibInclude = true
Use gtag - usegtag = true
Use push - usegtag = false

@brobatr
Copy link
Contributor Author

brobatr commented Nov 15, 2023

blocked by #2620

@brobatr
Copy link
Contributor Author

brobatr commented Nov 17, 2023

will create a new PR after #2620 is fixed

@brobatr brobatr closed this Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants