If you're adding a script to your school that expects dynamic (not hardcoded) values, then you'll use Pathwright events. When a Pathwright event fires, the callback function will be supplied with the expected data for that event. Each Pathwright event has its own set of expected data, so be sure to write your callback function with that in mind.

Pathwright events example

Here's an example of a Google Analytics script that requires the current user's ID. Say we want to run this Google Analytics script on initial page load and any time the current user changes (after user signs in or signs out).

We can do that using the "pathwright:ready" and "user:signed:in" Pathwright events.

"pathwright:ready" – executes on initial page load and supplies the current user data to the event callback function.

"user:signed:in" – executes after a user signs in and supplies the current user data to the event callback function.

Here's how we can handle these events:

<!-- Conditionally execute a Google Analytics script if an authenticated user exists following initial page load when pathwright context data becomes available -->

<script>
document.addEventListener("pathwright:ready", function (e) {
if (e.detail.user) {
ga('create', 'UA-XXXXX-Y', 'auto', {
userId: e.detail.user.id
})
}
})
</script>
<!-- Execute a Google Analytics script after user authenticates -->

<script>
document.addEventListener("user:signed:in", function (e) {
ga('create', 'UA-XXXXX-Y', 'auto', {
userId: e.detail.user.id
})
})
</script>

How to add custom scripts 

Open "Settings" from the main menu and go to Connect other apps > Add custom code & pixel tracking.

More Pathwright Events

When viewing your custom scripts, below the "header" and "body" code boxes you'll find an additional code box that lists out the available Pathwright events. After selecting an event, the code box will update with the event script and comments regarding the expected data that is supplied to that event when the event fires.

You can copy and paste this code into the "header" or "body" code box above and make any edits necessary.

Did this answer your question?