Track page views

Page views are events that record when a user visits a page on your site. When you send us page view data, you can segment your users based on pages they have or have not visited.

Capture page views

To capture page view events, add our JavaScript snippet to your site. We will track page views on any page where that snippet is present. The event name of a page view event is the URL of the page that a person visited.

The JavaScript snippet also turns URL parameters into event data, helping you capture additional information about page views—a user’s search terms, products that a person has filtered for, dates that a user is interested in, etc.

You can also send page view events through our API. If your account is based in the EU, make sure you send requests to track-eu.customer.io.

curl -i https://track.customer.io/api/v1/customers/5/events \
-u YOUR-SITE-ID-HERE:YOUR-SECRET-API-KEY-HERE \
-d name=http://google.com/search \
-d type=page \
-d data[referrer]=http://google.com

URL parameters in pageview events

The JavaScript snippet captures URL parameters as event data, helping you capture additional information about page views—a user’s search terms, products that a person has filtered for, dates that a user is interested in, etc.

So, for example, a url in the format https://example.com/products?property1=stuff&property2=things. We capture property1 and property2 as event data. The resulting page view event looks like this:

{
    "property1": "stuff",
    "property2": "things"
}

The Events API does not automatically translate URL parameters to event properties. If you use the Events API and you want to segment based on URL parameters. In the example below, we’ve passed a page view event with a URL parameter called search_prop.

curl --request POST \
  --url https://track.customer.io/api/v1/customers/{identifier}/events \
  --header "Authorization: Basic $(echo -n site_id:api_key | base64)" \
  --header 'content-type: application/json' \
  --data '{"type":"page","name":"https://example.com","data":{"search-prop":"example-search"}}'

Create segments based on page views

  1. Go to Segments.

  2. Click Create Segment and create a Data-driven segment.

  3. Set a Page condition with URL matching and then set the URL you want to segment on. You can create segments based on pages users have or have not viewed.

    image.png
    image.png

    You can also click Refine, to segment page views based on a time frame or the number of times a person viewed a page e.g., “has not viewed in 30 days”, or “has viewed at least once”. You can also segment based on URL parameters that you captured by your event. The JavaScript snippet automatically captures URL parameters; if you send events using the Events API you must specify URL parameters in the data object.

    image.png
    image.png

Important things to know:

When defining the URL for a page view:

  • To track a specific page, enter the full path, like this: http://customer.io/docs/pageviews.html
  • To track any page, use the asterisk *
  • You can also use * as a wildcard to match anything before or after a URL, just like in the above screenshot. For example, http://customer.io/docs/* will track any page within the docs sub-directory
  • If you use the JavaScript snippet, we’ll automatically capture URL parameters as event data.
Copied to clipboard!