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

feat: add data attributes to script #466

Closed
wants to merge 1 commit into from

Conversation

dine
Copy link

@dine dine commented Jul 29, 2024

Some tools require a data attribute for consent management, for example:
https://support.didomi.io/enable-google-consent-mode-with-didomi-new-flow#gcm_didomi_console

Maybe related to issue: gtm-support/vue-gtm#434

@dine dine requested a review from Shinigami92 as a code owner July 29, 2024 12:14
@dine dine force-pushed the support-data-attributes branch from e918213 to e149aa9 Compare July 29, 2024 12:23
@dine dine force-pushed the support-data-attributes branch from e149aa9 to 21a4129 Compare July 29, 2024 12:31
@Shinigami92 Shinigami92 added the enhancement New feature or request label Jul 29, 2024
@@ -1,4 +1,5 @@
import type { GtmIdContainer, GtmQueryParams } from './gtm-container';
import { type DataAttributes } from './utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion:

Suggested change
import { type DataAttributes } from './utils';
import type { DataAttributes } from './utils';

/**
* Will add data attributes to script tag.
*/
dataAttributes?: DataAttributes[]
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion:

Suggested change
dataAttributes?: DataAttributes[]
dataAttributes?: DataAttributes[];

Comment on lines +153 to +155
config.dataAttributes.forEach(({ name, value }) => {
script.setAttribute(`data-${name}`, value);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion:

Suggested change
config.dataAttributes.forEach(({ name, value }) => {
script.setAttribute(`data-${name}`, value);
});
for ({ name, value } of config.dataAttributes) {
script.setAttribute(`data-${name}`, value);
}

@@ -160,6 +161,40 @@ describe('utils', () => {
},
);

// Test dataAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: this comment is not needed

Suggested change
// Test dataAttributes

@@ -16,6 +16,11 @@ export interface OnReadyOptions {
script: HTMLScriptElement;
}

export interface DataAttributes {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion:
interfaces should use singular

Suggested change
export interface DataAttributes {
export interface DataAttribute {

async: true,
defer: false,
nonce: '',
dataAttributes,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (blocking): you are passing, but it is not used right now at all
please change the expectScriptToBeCorrect to test internally for data attribute correctness

@dine
Copy link
Author

dine commented Jul 30, 2024

Hi @Shinigami92
It turns out the data attribute works only for loading the Google Analytics script, not the Google Tag Manager.
https://developers.didomi.io/cmp/web-sdk/third-parties/no-tag-manager#consent-to-vendors
Screenshot 2024-07-30 at 14 37 28
So maybe this doesn't make sense. Thanks for the review anyway!

@dine dine closed this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants