Add function setConsent() to set end user consent state for web apps … · firebase/firebase-js-sdk@1d3a34d (original) (raw)

`@@ -15,11 +15,19 @@

`

15

15

` * limitations under the License.

`

16

16

` */

`

17

17

``

18

``

`-

import { CustomParams, ControlParams, EventParams } from './public-types';

`

``

18

`+

import {

`

``

19

`+

CustomParams,

`

``

20

`+

ControlParams,

`

``

21

`+

EventParams,

`

``

22

`+

ConsentSettings

`

``

23

`+

} from './public-types';

`

19

24

`import { DynamicConfig, DataLayer, Gtag, MinimalDynamicConfig } from './types';

`

20

25

`import { GtagCommand, GTAG_URL } from './constants';

`

21

26

`import { logger } from './logger';

`

22

27

``

``

28

`+

// Possible parameter types for gtag 'event' and 'config' commands

`

``

29

`+

type GtagConfigOrEventParams = ControlParams & EventParams & CustomParams;

`

``

30

+

23

31

`/**

`

24

32

` * Makeshift polyfill for Promise.allSettled(). Resolves when all promises

`

25

33

` * have either resolved or rejected.

`

`@@ -219,9 +227,9 @@ function wrapGtag(

`

219

227

` * @param gtagParams Params if event is EVENT/CONFIG.

`

220

228

` */

`

221

229

`async function gtagWrapper(

`

222

``

`-

command: 'config' | 'set' | 'event',

`

``

230

`+

command: 'config' | 'set' | 'event' | 'consent',

`

223

231

`idOrNameOrParams: string | ControlParams,

`

224

``

`-

gtagParams?: ControlParams & EventParams & CustomParams

`

``

232

`+

gtagParams?: GtagConfigOrEventParams | ConsentSettings

`

225

233

`): Promise {

`

226

234

`try {

`

227

235

`// If event, check that relevant initialization promises have completed.

`

`@@ -232,7 +240,7 @@ function wrapGtag(

`

232

240

`initializationPromisesMap,

`

233

241

`dynamicConfigPromisesList,

`

234

242

`idOrNameOrParams as string,

`

235

``

`-

gtagParams

`

``

243

`+

gtagParams as GtagConfigOrEventParams

`

236

244

`);

`

237

245

`} else if (command === GtagCommand.CONFIG) {

`

238

246

`// If CONFIG, second arg must be measurementId.

`

`@@ -242,8 +250,11 @@ function wrapGtag(

`

242

250

`dynamicConfigPromisesList,

`

243

251

`measurementIdToAppId,

`

244

252

`idOrNameOrParams as string,

`

245

``

`-

gtagParams

`

``

253

`+

gtagParams as GtagConfigOrEventParams

`

246

254

`);

`

``

255

`+

} else if (command === GtagCommand.CONSENT) {

`

``

256

`+

// If CONFIG, second arg must be measurementId.

`

``

257

`+

gtagCore(GtagCommand.CONSENT, 'update', gtagParams as ConsentSettings);

`

247

258

`} else {

`

248

259

`// If SET, second arg must be params.

`

249

260

`gtagCore(GtagCommand.SET, idOrNameOrParams as CustomParams);

`