1515 * limitations under the License.
1616 */
1717
18- import { CustomParams , ControlParams , EventParams } from './public-types' ;
18+ import {
19+ CustomParams ,
20+ ControlParams ,
21+ EventParams ,
22+ ConsentSettings
23+ } from './public-types' ;
1924import { DynamicConfig , DataLayer , Gtag , MinimalDynamicConfig } from './types' ;
2025import { GtagCommand , GTAG_URL } from './constants' ;
2126import { logger } from './logger' ;
2227
28+ // Possible parameter types for gtag 'event' and 'config' commands
29+ type GtagConfigOrEventParams = ControlParams & EventParams & CustomParams ;
30+
2331/**
2432 * Makeshift polyfill for Promise.allSettled(). Resolves when all promises
2533 * have either resolved or rejected.
@@ -219,9 +227,9 @@ function wrapGtag(
219227 * @param gtagParams Params if event is EVENT/CONFIG.
220228 */
221229 async function gtagWrapper (
222- command : 'config' | 'set' | 'event' ,
230+ command : 'config' | 'set' | 'event' | 'consent' ,
223231 idOrNameOrParams : string | ControlParams ,
224- gtagParams ?: ControlParams & EventParams & CustomParams
232+ gtagParams ?: GtagConfigOrEventParams | ConsentSettings
225233 ) : Promise < void > {
226234 try {
227235 // If event, check that relevant initialization promises have completed.
@@ -232,7 +240,7 @@ function wrapGtag(
232240 initializationPromisesMap ,
233241 dynamicConfigPromisesList ,
234242 idOrNameOrParams as string ,
235- gtagParams
243+ gtagParams as GtagConfigOrEventParams
236244 ) ;
237245 } else if ( command === GtagCommand . CONFIG ) {
238246 // If CONFIG, second arg must be measurementId.
@@ -242,8 +250,11 @@ function wrapGtag(
242250 dynamicConfigPromisesList ,
243251 measurementIdToAppId ,
244252 idOrNameOrParams as string ,
245- gtagParams
253+ gtagParams as GtagConfigOrEventParams
246254 ) ;
255+ } else if ( command === GtagCommand . CONSENT ) {
256+ // If CONFIG, second arg must be measurementId.
257+ gtagCore ( GtagCommand . CONSENT , 'update' , gtagParams as ConsentSettings ) ;
247258 } else {
248259 // If SET, second arg must be params.
249260 gtagCore ( GtagCommand . SET , idOrNameOrParams as CustomParams ) ;
0 commit comments