2024年6月4日 星期二

Integrating Partytown without using npm

1. Download Partytown Library Files

First, you need to download the Partytown library files into your project. Use the following command to copy the library files to your desired location:


npx @builder.io/partytown copylib --no-debug /path/to/your/project/public/partytown}

Replace /path/to/your/project/public/partytown with the actual path where you want to store the Partytown library files.

2. Generate the Partytown Snippet

Next, generate the Partytown snippet using the Node.js command:


node -e "import('@builder.io/partytown/integration').then(({ partytownSnippet }) => console.log(partytownSnippet({forward:['dataLayer.push'],lib:'/partytown/'})))"

Replace /partytown/ with the correct path relative to your website’s root where the Partytown files are hosted.

3. Integrate the Snippet into Your HTML

Copy the generated snippet and paste it into the <head> section of your HTML file. Here’s an example:


<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Using Partytown</title>

<script>

// Paste the generated Partytown snippet here

</script>

</head>

<body>

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

</body>

</html>

Summary

  1. Download Partytown library files using npx @builder.io/partytown copylib.

  2. Generate the Partytown snippet with the appropriate path using the Node.js command.

  3. Integrate the generated snippet into your HTML <head> section.

沒有留言:

張貼留言