You can add tracking code to monitor how site visitors interact with your site. This gives you insight into your site visitors' online behavior and can help you optimize your online marketing strategies.
By the end of this tutorial, you'll have a site that sends custom events to an analytics tool (like Google Analytics) whenever a site visitor clicks the download button on your site.
You'll use the following steps to send a tracking event from your page code:
The code in this article was written using the following module versions:
Learn how to install npm packages in the editor or using the CLI.
Note
Connect the desired tracking and analytics tool to your site. This tutorial connects to Google Analytics, but the same concepts apply when connecting to Meta Pixel.
Add the following elements to your page:
docRepeater.docTitle.downloadButton.docData.Connect elements to your data.
Query the docData collection and use the results to populate the repeater and its repeated elements.
The result should look like this:

Import the window module.
Add this import statement at the top of your page code:
Add an onClick() event to the repeated download button.
Add an onClick() event handler to the repeater's onReady() handler:
Call the trackEvent() method.
Add the tracking code inside the onClick() event. This sends Google Analytics a custom event that indicates a download occurred.
When sending a custom event to Google Analytics, use these parameters:
| Key | Value Type | Required | Usage |
|---|---|---|---|
eventCategory | string | yes | Object that was interacted with |
eventAction | string | yes | Type of interaction |
eventLabel | string | no | Event category |
eventValue | number | no | Numeric value associated with the event |
Now, when a user clicks the download button, you'll see an event registered in your analytics tool.
Here's the complete code for your page:
To learn more about the types of events you can send and their corresponding parameters, see trackEvent( ) in the API Reference.