-
Notifications
You must be signed in to change notification settings - Fork 287
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
Example: Partytown + Google Tag Manager + CSP #1548
Closed
Closed
Conversation
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
juanpprieto
force-pushed
the
juanpprieto/example-partytown
branch
from
December 6, 2023 00:47
e348e86
to
92c862b
Compare
Ad.. . .
juanpprieto
force-pushed
the
juanpprieto/example-partytown
branch
from
December 6, 2023 00:56
92c862b
to
6a2fc95
Compare
blittle
reviewed
Dec 6, 2023
Co-authored-by: Bret Little <[email protected]>
Co-authored-by: Bret Little <[email protected]>
Co-authored-by: Bret Little <[email protected]>
Co-authored-by: Bret Little <[email protected]>
benjaminsehl
reviewed
Dec 7, 2023
Co-authored-by: Benjamin Sehl <[email protected]>
Merged
Replaced with #1683 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hydrogen example: Partytown + Google Tag Manager + CSP
This folder contains a peformance-oriented example lazy-loading Google Tag Manager
using Partytown.
Party town helps relocate resource intensive scripts into a web worker, and off of the main thread.
Its goal is to help speed up sites by dedicating the main thread to your code, and offloading third-party scripts to a web worker.
Requirements
Key files
This folder contains the minimal set of files needed to showcase the implementation.
Files that aren’t included by default with Hydrogen and that you’ll need to
create are labeled with 🆕.
.env.example
.env
file, if you have one.app/components/PartytownGoogleTagManager.tsx
app/utils/partytown/maybeProxyRequest.ts
app/utils/partytown/partytownAtomicHeaders.ts
app/routes/reverse-proxy.ts
app/root.tsx
app/routes/_index.tsx
pageView
event is emmitedapp/entry.server.tsx
Dependencies
Instructions
1. Install required dependencies
2. Modify npm scripts
In
package.json
modify thebuild
script and add thepartytown
scriptAdd the
partytown
script which copies the library files to/public
"scripts": { + "partytown": "partytown copylib public/~partytown" },
Modify the
build
script to copy the partytown library files to/public
before every buildView the complete component file to see these updates in context.
3. Copy the library files
4. Copy over the new files
.env
file, copy over these key-value pairs:GTM_CONTAINER_ID
- To obtain your GTM container ID follow these instructions5. Edit the
root.tsx
layout fileImport the required components and utilties
Update the
loader
functionUpdate the App component
View the complete component file to see these updates in context.
6. (Optional) - Update Content Securirt Policy
Add
wwww.googletagmanager.com
domain to thescriptSrc
directiveView the complete component file to see these updates in context.
7. (TypeScript only) - Add the new environment variable to the
ENV
type definitionUpdate the
remix.d.ts
file// ...other code declare global { /** * A global `process` object is only available during build to access NODE_ENV. */ const process: {env: {NODE_ENV: 'production' | 'development'}}; /** * Declare expected Env parameter in fetch handler. */ interface Env { SESSION_SECRET: string; PUBLIC_STOREFRONT_API_TOKEN: string; PRIVATE_STOREFRONT_API_TOKEN: string; PUBLIC_STORE_DOMAIN: string; PUBLIC_STOREFRONT_ID: string; + GTM_CONTAINER_ID: `GTM-${string}`; } } // ...other code
View the complete component file to see these updates in context.