Partytown implementation with React.js

2.3k Views Asked by At

I was trying to implement partytown in a React application but the partytown documentation is not clear and I am unable to find a good resource for partytown implementation. Please guide on how to implement partytown in React with a good example. Also, is there any way to check if partytown is implemented or not

1

There are 1 best solutions below

2
Usman Hassan On

In React application the party-town library can be used in the script tag to run 3rd party scripts.

Example:

<script
  type="text/partytown"
  dangerouslySetInnerHTML={{
    __html: '/* Write your Script here*/',
  }}
/>

Or you can use this method to run an external Script.

 <script src="https://example.com/analytics.js" type="text/partytown" />

But for your code to be executed you need to import the Partytown component and set some configurations.

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

export function Head() {
  return (
    <>
      <Partytown debug={true} forward={['dataLayer.push']} />
    </>
  );
}

You can go through the documentation here to see the list of configuration options available to you.