Example: Manually Track Pageviews with Sailthru JS and Google Tag Manager
This page offers an example implementation of the Sailthru.track() function, however, your requirements and preferred method for implementing the function may vary. For more information, see the function documentation.
You can log a pageview using the Sailthru.track function at any time. This is typically used when autoTrackPageview is set to false in the Sailthru.init function. Note that if you leave autoTrackPageview set to true and use Sailthru.track, multiple pageviews will be logged. For instructions on how to configure the Sailthru.init function using Google Tag Manager, see the Introduction.
1. Add Sailthru.track Function as a Tag
- In Google Tag Manager, click New Tag, then change the tag’s name from “Untitled Tag” to “Sailthru.track”.
- Copy the code sample below and paste it into the HTML box. We are manually logging a pageview to the URL http://example.com/test.
- Scroll down below the HTML field and click within the Triggering box to add a new trigger, so that Google Tag Manager knows when to fire the tag.
2. Trigger the Tag on Pageview
- After you click in the Triggering box, at the top-right, click to add a new trigger.
- If you’re using a single-page, infinite scroll site you can create a trigger that fires on all pages. Select Add Trigger and select All Pages.
- If you only want this to fire on a certain page, for example a page located at /products you can configure the trigger and Sailthru Track call to only fire on those pages.
- You can optionally give your new trigger a name in the top-left corner.
- Click Save.
The Sailthru track functionality puts a lot of control in your hands, and as an advanced user when combined with Google Tag Manager it can become a very useful tool to add.