Skip to content

Commit e5a7b73

Browse files
committed
Update types, documentation and functionality
1 parent fbf2348 commit e5a7b73

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

packages/analytics/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ export type CustomEventName<T> = T extends EventNameString ? never : T;
725725
*
726726
* Use the {@link ConsentSettings} to specify individual consent type values. By default consent
727727
* types are set to "granted".
728-
*
728+
* @public
729729
* @param consentSettings Maps the applicable end user consent state for gtag.js.
730730
*/
731731
export function setConsent(consentSettings: ConsentSettings): void {

packages/analytics/src/functions.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,7 @@ export let defaultConsentSettingsForInit: ConsentSettings | undefined;
156156
* @param consentSettings Maps the applicable end user consent state for gtag.js.
157157
*/
158158
export function _setConsentDefaultForInit(
159-
consentSettings: ConsentSettings
159+
consentSettings?: ConsentSettings
160160
): void {
161-
if (defaultConsentSettingsForInit) {
162-
defaultConsentSettingsForInit = {
163-
...defaultConsentSettingsForInit,
164-
...consentSettings
165-
};
166-
} else {
167-
defaultConsentSettingsForInit = consentSettings;
168-
}
161+
defaultConsentSettingsForInit = consentSettings;
169162
}

packages/analytics/src/initialize-analytics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import {
2828
import { ERROR_FACTORY, AnalyticsError } from './errors';
2929
import { findGtagScriptOnPage, insertScriptTag } from './helpers';
3030
import { AnalyticsSettings } from './public-types';
31-
import { defaultConsentSettingsForInit } from './functions';
31+
import {
32+
defaultConsentSettingsForInit,
33+
_setConsentDefaultForInit
34+
} from './functions';
3235

3336
async function validateIndexedDB(): Promise<boolean> {
3437
if (!isIndexedDBAvailable()) {
@@ -122,6 +125,7 @@ export async function _initializeAnalytics(
122125
// Detects if there are consent settings that need to be configured.
123126
if (defaultConsentSettingsForInit) {
124127
gtagCore(GtagCommand.CONSENT, 'default', defaultConsentSettingsForInit);
128+
_setConsentDefaultForInit(undefined);
125129
}
126130

127131
// This command initializes gtag.js and only needs to be called once for the entire web app,

packages/analytics/src/public-types.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,29 @@ export interface EventParams {
289289
[key: string]: unknown;
290290
}
291291

292-
/** Maps the applicable end user consent state. */
292+
/**
293+
* Consent status settings for each consent type.
294+
* @public
295+
*/
293296
export interface ConsentSettings {
297+
// Enables storage, such as cookies, related to advertising
294298
ad_storage?: ConsentStatusString;
299+
// Enables storage, such as cookies, related to analytics (for example, visit duration)
295300
analytics_storage?: ConsentStatusString;
301+
// Enables storage that supports the functionality of the website or app such as language settings
302+
functionality_storage?: ConsentStatusString;
303+
// Enables storage related to personalization such as video recommendations
304+
personalization_storage?: ConsentStatusString;
305+
// Enables storage related to security such as authentication functionality, fraud prevention,
306+
// and other user protection
307+
security_storage?: ConsentStatusString;
308+
[key: string]: unknown;
296309
}
297310

298311
/* eslint-enable camelcase */
299312

300-
/** Whether a particular consent type has been granted or denied. */
313+
/**
314+
* Whether a particular consent type has been granted or denied.
315+
* @public
316+
*/
301317
export type ConsentStatusString = 'granted' | 'denied';

0 commit comments

Comments
 (0)