-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6827e06
commit 8f0c6ee
Showing
13 changed files
with
382 additions
and
245 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,4 +4,5 @@ node_modules/ | |
/lib/ | ||
/react/ | ||
/tests/~partytown/ | ||
/tests/videos/ | ||
/tests/videos/ | ||
/tsc/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 @@ | ||
/** | ||
* https://developers.google.com/tag-manager/quickstart | ||
*/ | ||
export const googleTagManager = (containerId: string) => ` | ||
/* Google Tag Manager */ | ||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer',${JSON.stringify( | ||
containerId | ||
)}); | ||
/* End Google Tag Manager */`; |
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,9 @@ | ||
export { PT_SCRIPT_TYPE } from '../lib/utils'; | ||
|
||
export const appendForwardConfig = (forwardConfig: string) => | ||
[ | ||
`(function(w,p,f,c){`, | ||
`c=w[p]=w[p]||{};`, | ||
`(c[f]=c[f]||[]).push(${JSON.stringify(forwardConfig)})`, | ||
`})(window,'partytown','forward');`, | ||
].join(''); |
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 was deleted.
Oops, something went wrong.
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,7 @@ | ||
export { Partytown, PartytownProps } from './partytown'; | ||
|
||
export { | ||
GoogleTagManager, | ||
GoogleTagManagerNoScript, | ||
GoogleTagManagerProps, | ||
} from './integrations/gtm'; |
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
import React, { Fragment } from 'react'; | ||
import { googleTagManager } from '../../integrations/gtm'; | ||
import { appendForwardConfig, PT_SCRIPT_TYPE } from '../../integrations/utils'; | ||
|
||
/** | ||
* https://developers.google.com/tag-manager/quickstart | ||
* | ||
* @public | ||
*/ | ||
export type GoogleTagManagerProps = { | ||
/** | ||
* Google Tag Manager Container ID, formatted as GTM-XXXXXX | ||
*/ | ||
containerId: string; | ||
}; | ||
|
||
/** | ||
* The Google Tag Manager Partytown component should be added after the opening `<head>` | ||
* tag, but before the `<Partytown/>` component. This component will add the | ||
* [Data Layer](https://developers.google.com/tag-manager/devguide) to the main thread | ||
* window, and will load GTM within the web worker. Any updates to `dataLayer.push(...)` | ||
* will be forwarded to the Partytown web worker. | ||
* | ||
* https://developers.google.com/tag-manager/quickstart | ||
* | ||
* @public | ||
*/ | ||
export const GoogleTagManager = ({ containerId }: GoogleTagManagerProps): any => ( | ||
<Fragment> | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: appendForwardConfig('dataLayer.push'), | ||
}} | ||
/> | ||
<script | ||
type={PT_SCRIPT_TYPE} | ||
dangerouslySetInnerHTML={{ | ||
__html: googleTagManager(containerId), | ||
}} | ||
/> | ||
</Fragment> | ||
); | ||
|
||
/** | ||
* The GTM No Script component should be added immediately after the opening `<body>` tag. | ||
* | ||
* https://developers.google.com/tag-manager/quickstart | ||
* | ||
* @public | ||
*/ | ||
export const GoogleTagManagerNoScript = ({ containerId }: GoogleTagManagerProps): any => ( | ||
<noscript> | ||
<iframe | ||
src={'https://www.googletagmanager.com/ns.html?id=' + encodeURIComponent(containerId)} | ||
height="0" | ||
width="0" | ||
style={{ display: 'none', visibility: 'hidden' }} | ||
></iframe> | ||
</noscript> | ||
); |
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,43 @@ | ||
import React from 'react'; | ||
import type { PartytownConfig } from '../lib/types'; | ||
import PartytownSnippet from '@snippet'; | ||
|
||
/** | ||
* Props for `<Partytown/>`, which extends the Partytown Config. | ||
* | ||
* https://github.com/BuilderIO/partytown#config | ||
* | ||
* @public | ||
*/ | ||
export interface PartytownProps extends PartytownConfig {} | ||
|
||
/** | ||
* The React `<Partytown/>` component should be placed within the `<head>` | ||
* of the document, and after any integrations such as `<GoogleTagManager/>`. | ||
* | ||
* @public | ||
*/ | ||
export const Partytown = (props?: PartytownProps): any => { | ||
props = { ...props }; | ||
const forward = props.forward || []; | ||
delete props.forward; | ||
|
||
const config = [ | ||
`(function(w,p,f,c){`, | ||
Object.keys(props).length > 0 | ||
? `c=w[p]=Object.assign(w[p]||{},${JSON.stringify(props)});` | ||
: `c=w[p]=w[p]||{};`, | ||
`c[f]=(c[f]||[])`, | ||
forward.length > 0 ? `.concat(${JSON.stringify(forward)})` : ``, | ||
`})(window,'partytown','forward');`, | ||
]; | ||
|
||
return ( | ||
<script | ||
data-partytown="lib" | ||
dangerouslySetInnerHTML={{ | ||
__html: config.join('') + PartytownSnippet, | ||
}} | ||
/> | ||
); | ||
}; |
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