-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build local copy of Digital Analytics Program (#11097)
* Build local copy of Digital Analytics Program changelog: Internal, Performance, Optimize loading of Digital Analytics Program script * Remove CSP exceptions for DAP CDN * Download and patch DAP as postinstall * Consistently return string value from UriService#add_params * Add spec to load DAP script * Update DAP script test to check syntax error on load DAP script has too many side effects and manipulates DOM in a way that's hard to clean up. Absent some other way to create an isolated DOM, at least check that the script can be evaluated without syntax errors. * Add DAP script to ESLint ignore * Add test for url_params behavior * Better coverage for combination url_params and attributes * Treat url_params as distinct property See: #11097 (comment) Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com> * Use conventional capitalization See: https://github.com/18F/identity-idp/blob/main/docs/frontend.md#naming-conventions * Separate download and patch tasks to cache-bust by SHA * Ignore DAP script in TypeScript checks * Use more Makefile wizardry to generate compiled DAP Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com> * Run analytics postinstall using Yarn cwd In production environments, `yarn install --production` won't make workspaces available, so trying to use `yarn workspace ...` will fail. This achieves the same effect without relying on the workspace being "installed" * Try avoiding default NPM lifecycle script names * Test using full install in cwd package * Try incorporating analytics tasks in build:js In CI Dockerfile, app files aren't available at time of install. This also aligns closer to how browsers.json is generated * Combine make tasks in build:js * Force analytics task in top-level Makefile Defer to sub-process to decide what needs to be done * Split install and build tasks for analytics Avoid dependency on package code existing during install step * Copy Makefile earlier in Docker images * Try complete build if folder available * Revert to original postinstall approach --------- Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
- Loading branch information
1 parent
5bb3cc9
commit 85df0cf
Showing
17 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ public | |
vendor | ||
coverage | ||
doc | ||
app/javascript/packages/analytics/digital-analytics-program*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
digital-analytics-program*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DAP_SHA ?= 7c14bb3 | ||
|
||
digital-analytics-program.js: digital-analytics-program-$(DAP_SHA).js digital-analytics-program.patch | ||
patch -p1 $^ --output $@ | ||
|
||
digital-analytics-program-$(DAP_SHA).js: | ||
curl https://raw.githubusercontent.com/digital-analytics-program/gov-wide-code/$(DAP_SHA)/Universal-Federated-Analytics.js --silent --output $@ | ||
|
||
clean: | ||
rm digital-analytics-program-$(DAP_SHA).js digital-analytics-program.js | ||
|
||
.PHONY: clean |
8 changes: 8 additions & 0 deletions
8
app/javascript/packages/analytics/digital-analytics-program.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
73a74 | ||
> GA4Object.async = true; | ||
785d785 | ||
< var piiRegex = []; | ||
900c900 | ||
< piiRegex.forEach(function (pii) { | ||
--- | ||
> window.piiRegex.forEach(function (pii) { |
26 changes: 26 additions & 0 deletions
26
app/javascript/packages/analytics/digital-analytics-program.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Worker } from 'node:worker_threads'; | ||
import { join } from 'node:path'; | ||
import { pathToFileURL } from 'node:url'; | ||
|
||
describe('digital analytics program', () => { | ||
it('parses without syntax error', async () => { | ||
// Future: Replace with Promise.withResolvers once supported | ||
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers | ||
let resolve; | ||
const promise = new Promise((_resolve) => { | ||
resolve = _resolve; | ||
}); | ||
|
||
// Reference: https://github.com/nodejs/node/issues/30682 | ||
const toDataURL = (source: string) => | ||
new URL(`data:text/javascript,${encodeURIComponent(source)}`); | ||
const url = pathToFileURL(join(__dirname, './digital-analytics-program.js')); | ||
const code = `await import(${JSON.stringify(url)});`; | ||
new Worker(toDataURL(code)).on('error', (error) => { | ||
expect(error).not.to.be.instanceOf(SyntaxError); | ||
resolve(); | ||
}); | ||
|
||
await promise; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@18f/identity-analytics/digital-analytics-program'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters