Partytown is distributed from @builder.io/partytown using NPM. Within the distribution there are a few directories and submodules, each with their own purpose.

β”œβ”€β”€ integration/
β”œβ”€β”€ lib/
β”œβ”€β”€ react/
β”œβ”€β”€ services/
└── utils/


The lib directory contains the static files that should be hosted from the same origin as the website. Hosting from the same origin is a requirement of the service worker scope. The lib static files are minified and meant for production use.

β”œβ”€β”€ partytown-atomics.js
β”œβ”€β”€ partytown-media.js
β”œβ”€β”€ partytown-sw.js
└── partytown.js

The partytown.js file must be in the <head> before all other third-party scripts, and should not have the async or defer attributes. Because the script must be executed immediately, and since it’s such a small file, it’s always preferred to inline the partytown.js script content, rather than it being an additional http request.

Note: When the service worker is correctly installed, the service worker itself handles the request to the partytown-sandbox-sw.html file and provides the content. The network tab will show partytown-sandbox-sw.html, and the service worker provides the response, but the file itself is not in the distribution. If you receive a 404 for this file then it means the service worker is not installed correctly. Please try uninstalling any existing Partytown service workers and ensure the Partytown files are loading correctly.


The lib/debug directory has the same purpose as the lib, but instead will console log more information and the files themselves are not minified. Additionally, you’ll notice there are more debug files than the production lib files, and that’s because the production lib files inline many scripts. For example, the web worker script is inlined, rather than being a separate request.

The lib/debug files are not meant to be used in production. See the Partytown Configuration docs on how to enable debug mode.

β”œβ”€β”€ partytown-atomics.js
β”œβ”€β”€ partytown-media.js
β”œβ”€β”€ partytown-sandbox-sw.js
β”œβ”€β”€ partytown-sw.js
β”œβ”€β”€ partytown-ww-atomics.js
β”œβ”€β”€ partytown-ww-sw.js
└── partytown.js


The integration submodule provides functions that can be used for integrations.

partytownSnippet()Function that returns the Partytown snippet as a string which can be used as the innerHTML of the inlined Partytown script in the head.
SCRIPT_TYPEThe value for the script type attribute: text/partytown
import { partytownSnippet } from '@builder.io/partytown/integration';

const snippetText = partytownSnippet();


The react submodule is where you’ll find the React specific components, which is just a wrapper around the partytown.js snippet code. Please see the React docs for more information.

import { Partytown } from '@builder.io/partytown/react';

export function Head() {
  return (
      <Partytown />


The services submodule provides some of the commonly used forward events, such as Google Tag Manager or Facebook Pixel. Please see the Common Services docs for more information.


The utils submodule provides some convenience utilities, such as the the Copy Task CLI and API.

copyLibFiles(destDir)Async copy the lib directory to the destDir.
libDirPath()Returns an absolute path to the lib directory.
partytownRollup()Rollup plugin.
partytownVite()Vite plugin.
Made with ❀️ by

Β© 2024 Builder.io, Inc.

Introducing Visual Copilot.

100% free. Supports all popular frameworks.

Try Visual Copilot