-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
e918213
to
e149aa9
Compare
e149aa9
to
21a4129
Compare
@@ -1,4 +1,5 @@ | |||
import type { GtmIdContainer, GtmQueryParams } from './gtm-container'; | |||
import { type DataAttributes } from './utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
import { type DataAttributes } from './utils'; | |
import type { DataAttributes } from './utils'; |
/** | ||
* Will add data attributes to script tag. | ||
*/ | ||
dataAttributes?: DataAttributes[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
dataAttributes?: DataAttributes[] | |
dataAttributes?: DataAttributes[]; |
config.dataAttributes.forEach(({ name, value }) => { | ||
script.setAttribute(`data-${name}`, value); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
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 |
There was a problem hiding this comment.
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
// Test dataAttributes |
@@ -16,6 +16,11 @@ export interface OnReadyOptions { | |||
script: HTMLScriptElement; | |||
} | |||
|
|||
export interface DataAttributes { |
There was a problem hiding this comment.
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
export interface DataAttributes { | |
export interface DataAttribute { |
async: true, | ||
defer: false, | ||
nonce: '', | ||
dataAttributes, |
There was a problem hiding this comment.
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
Hi @Shinigami92 |
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