Track site search on web
Site search tracking are provided as part of the Site tracking plugin. This plugin also provides events for social media interactions and timings.
Site search events must be manually tracked.
Install plugin
- JavaScript (tag)
- Browser (npm)
| Tracker Distribution | Included |
|---|---|
sp.js | ✅ |
sp.lite.js | ❌ |
Download:
| Download from GitHub Releases (Recommended) | Github Releases (plugins.umd.zip) |
| Available on jsDelivr | jsDelivr |
| Available on unpkg | unpkg |
Note: The links to the CDNs above are pinned to a specific version at the time of writing. Check the plugin's GitHub releases for newer versions, and update the pinned version when you upgrade.
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-site-tracking@4.10.2/dist/index.umd.min.js",
["snowplowSiteTracking", "SiteTrackingPlugin"]
);
npm install @snowplow/browser-plugin-site-trackingyarn add @snowplow/browser-plugin-site-trackingpnpm add @snowplow/browser-plugin-site-tracking
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { SiteTrackingPlugin, trackSiteSearch } from '@snowplow/browser-plugin-site-tracking';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ SiteTrackingPlugin() ],
});
Event
Use the trackSiteSearch method to track users searching your website. Here are its arguments:
| Name | Required? | Description | Type |
|---|---|---|---|
terms | Yes | Search terms | array |
filters | No | Search filters | JSON |
totalResults | No | Results found | number |
pageResults | No | Results displayed on first page | number |
An example:
- JavaScript (tag)
- Browser (npm)
snowplow('trackSiteSearch', {
terms: ['unified', 'log'],
filters: {'category': 'books', 'sub-category': 'non-fiction'},
totalResults: 14,
pageResults: 8
});
import { trackSiteSearch } from '@snowplow/browser-plugin-site-tracking';
trackSiteSearch({
terms: ['unified', 'log'],
filters: {'category': 'books', 'sub-category': 'non-fiction'},
totalResults: 14,
pageResults: 8
});
Site search events are implemented as Snowplow self-describing events. Here is the schema for a site_search event.