Adding third-party scripts
In this guide, learn how to add third-party scripts to FastStore projects.
Third-party scripts are elements embedded in a webpage but served from a different domain than the one the user visits. Examples of these scripts include social media buttons, video players, ads, analytics tools, and other elements contributing to a more dynamic and interactive web experience.
Before you begin
Choose essential third-party scripts
To maintain your website's performance without compromising the functionality offered
by third-party scripts, consider incorporating only those third-party scripts that
enhance the value of your website.
Update the @faststore/core
version
Ensure your project uses
@faststore/core
version 2.1.82
or above. If not, follow these steps:- Open the FastStore code project.
- Navigate to the
package.json
file. - Find the
@faststore/core
package and change its version to2.1.82
. - In your terminal, run
yarn install
to update the package in the project.
Verify compatibility with Partytown
FastStore uses Partytown for script execution. Not all third-party scripts may be compatible with Partytown, so we strongly recommend testing third-party scripts with Partytown before implementing them. If any issues occur, avoid using those particular scripts.
Instructions
-
In your FastStore project, navigate to the
src
folder and create a folder namedscripts
. -
Within the
src/scripts
folder, create theThirdPartyScripts.tsx
file. -
In the
ThirdPartyScripts.tsx
file, add your script as the example below: -
Run
yarn dev
in the terminal to start the development server and execute the script you have added. -
Access the provided localhost URL in your browser, open the Developer Tools, and go to the
Console
tab. You should be able to see the message:🚀Hello from a third-party script!
: