Enable page view signals in the Connect web library
A page view represents an action that overwhelmingly changes or reloads the content presented to the user. You can send a page view signal using the Connect library to register page views as users are browsing your website. This signal type is the easiest to implement.
Availability
The page view signal is supported by Premium and Ultimate subscriptions.
Configuration
The Connect library provides a method, TLT.logSignal()
with which to send the signal to the Acoustic Connect endpoint, as a JSON object.
There are many possible ways to gather the data to populate the fields in the signal before sending it. You could read the data layer and collect information from there. Or you may choose to scrape the page category value from the web page. Or, as in the following example, you could collect the URL and page category from the browser address bar, provided your URLs are structured to include product categories.
Required fields
The logSignal
method requires the following fields.
Field | Values | Definition |
---|---|---|
category | String. Valid value - Behavior . | The category of the signal. Do not edit. |
effect | String. Valid values: - negative - positive | Specify how to interpret the signal. The value will be used for engagement index scoring. |
name | String, up to 256 characters | Assign a name to the signal to differentiate it from other signals. |
signalType | String. Valid value - pageView . | The type of signal to enable. Do not edit. |
url | String | The URL of the page a user has opened. You must provide a value for this field, or the signal will be ignored. |
Optional fields
You can include some optional fields to the configuration.
Field | Values | Definition |
---|---|---|
pageCategory | String | The category that the page belongs to. For example, the library can parse the URL or get the category from the data layer. |
Example
// Check that the Connect library is present
if (window.TLT && window.TLT.isInitialized()) {
const href = window.location.href;
const signal = {
signalType: "pageView",
name: "pageView generated by web site",
category: "Behavior",
url: "", // Required
pageCategory: "",
effect: "positive", // Required, must be "positive" or "negative"
signalCustomAttributes: []
};
// Capture URL, trim off the query string if present
signal.url = href.split("?")[0];
// Get category from URL fragment, e.g. /clothing/
let category = window.location.href.split("/")[3] || "";
if (!category) {
category = "home"; // Handle homepage case
}
if (category.indexOf("s?searchTerm=") !== -1) {
category = "search results"; // Handle search results page case
}
signal.pageCategory = category;
// Optional: display signal in console
console.log("pageView signal: " + JSON.stringify(signal, undefined, 2));
// Send signal to Acoustic
window.TLT.logSignal(signal);
}
Updated 1 day ago