Skip to content

Used Trust Types When API is available for gtag URL creation #7052

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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4cf1388
Initial fix for Trusted Types failures
dwyfrequency Feb 22, 2023
9222f5e
Add Trusted-Types
dwyfrequency Feb 22, 2023
ac387ac
Sanitize input
dwyfrequency Feb 22, 2023
53781ab
Add check for gtag url and log error if not found
dwyfrequency Feb 27, 2023
6c30bd6
Add test and exported function
dwyfrequency Mar 8, 2023
39a6958
Add changeset
dwyfrequency Mar 9, 2023
86c0f2c
Update comment
dwyfrequency Mar 9, 2023
516a70d
Merge branch 'master' into jd-trusted-types-7048
dwyfrequency Mar 12, 2023
dc7b7f1
Created function to create policy
dwyfrequency Mar 21, 2023
80ae05e
Stub logger instead of console.log
dwyfrequency Mar 21, 2023
ff564c7
Remove returns keyword in function docstring
dwyfrequency Mar 22, 2023
5316071
Updated the changeset for OR queries to be more descriptive (#7121)
MarkDuckworth Mar 14, 2023
cc82816
New way to config Firestore SDK Cache. (#7015)
wu-hui Mar 15, 2023
f8437f5
Enable bundle spec tests for ios (#7096)
wu-hui Mar 15, 2023
715ee9b
Add a TODO (#7103)
wu-hui Mar 15, 2023
8bad12d
Change _fail to use NETWORK_REQUEST_FAILED (#7125)
NhienLam Mar 16, 2023
1794678
firestore: verify DOMException exists before using it in when base64 …
dconeybe Mar 16, 2023
c3f3f61
Version Packages (#7123)
google-oss-bot Mar 16, 2023
54035e6
remove gapi.auth fall back option for getAuthToken() (#7100)
milaGGL Mar 17, 2023
e755eae
Update dependency simple-git to v3.16.0 [SECURITY] (#6986)
renovate[bot] Mar 17, 2023
f8334ae
Update dependency webpack to v5.76.0 [SECURITY] (#7127)
renovate[bot] Mar 17, 2023
be8b265
chore(deps): update endbug/add-and-commit action to v9 (#6425)
renovate[bot] Mar 17, 2023
cc3c93a
Add changeset (#7137)
hsubox76 Mar 20, 2023
b26c072
Firestore: query.test.ts: add a test that resumes a query with existe…
dconeybe Mar 20, 2023
8a1f7a4
Unmangle a switch variable for Closure (#7136)
hsubox76 Mar 21, 2023
ee6cc36
Remove dependency merge conflicts.
dwyfrequency Feb 22, 2023
62f0a42
Remove duplicate types package
dwyfrequency Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@types/sinon": "9.0.11",
"@types/sinon-chai": "3.2.9",
"@types/tmp": "0.2.3",
"@types/trusted-types": "2.0.3",
"@types/yargs": "17.0.13",
"@typescript-eslint/eslint-plugin": "5.43.0",
"@typescript-eslint/eslint-plugin-tslint": "5.43.0",
Expand Down
15 changes: 14 additions & 1 deletion packages/analytics/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import { logger } from './logger';
// Possible parameter types for gtag 'event' and 'config' commands
type GtagConfigOrEventParams = ControlParams & EventParams & CustomParams;

// Create a TrustedTypes policy that we use for scripts
let _ttPolicy: Partial<TrustedTypePolicy>;
if (window.trustedTypes) {
_ttPolicy = window.trustedTypes.createPolicy('firebase-js-sdk-policy', {
createScriptURL: (url: string) => url
});
}

/**
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises
* have either resolved or rejected.
Expand All @@ -51,7 +59,12 @@ export function insertScriptTag(
const script = document.createElement('script');
// We are not providing an analyticsId in the URL because it would trigger a `page_view`
// without fid. We will initialize ga-id using gtag (config) command together with fid.
script.src = `${GTAG_URL}?l=${dataLayerName}&id=${measurementId}`;

const gtagScriptURL = `${GTAG_URL}?l=${dataLayerName}&id=${measurementId}`;
(script.src as string | TrustedScriptURL) = _ttPolicy
? (_ttPolicy as TrustedTypePolicy)?.createScriptURL(gtagScriptURL)
: gtagScriptURL;

script.async = true;
document.head.appendChild(script);
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,11 @@
resolved "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.1.tgz#8f80dd965ad81f3e1bc26d6f5c727e132721ff40"
integrity sha512-Y0K95ThC3esLEYD6ZuqNek29lNX2EM1qxV8y2FTLUB0ff5wWrk7az+mLrnNFUnaXcgKye22+sFBRXOgpPILZNg==

"@types/[email protected]":
version "2.0.3"
resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz#a136f83b0758698df454e328759dbd3d44555311"
integrity sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==

"@types/vinyl@^2.0.4":
version "2.0.6"
resolved "https://registry.npmjs.org/@types/vinyl/-/vinyl-2.0.6.tgz#b2d134603557a7c3d2b5d3dc23863ea2b5eb29b0"
Expand Down