Scripts like GTM have a massive negative impact on performance and pagespeed, to remedy this scripts like Partytown have been made. Which allows you to keep your analytics but reclaim some of the performance.
Installation
- Install using
composer require justbetter/statamic-partytown
- Execute
yarn add @builder.io/partytown
- Configure Vite (or your other compiler) to copy the partytown files (however instead of dist it should go in public)
- Add
/public/~partytown
to your .gitignore
Load Partytown in on your head
If you're using antlers you should add the following to your head
<head>
...
{{ partial:if_exists src="statamic-partytown::head" }}
...
</head>
and in case of blade you can include it using the following
<head>
...
@include('statamic-partytown::head')
...
</head>
Optional
If you want to manage and add scripts to the page with partytown outside of your own built templates you can publish the Partytown Settings global:
php artisan vendor:publish --provider="Justbetter\StatamicPartytown\ServiceProvider" --tag=statamic-content
Usage
Partytown is running by default if you are running your site on https.
To use Partytown simply change the scripts you want to run in partytown from `` tags.