Sending pageviews
Reminder: ー A pageview is when a web user visits a page (sometimes called “hit” or “pagehit”). Notably, it automatically contains the current URL of the page, the screen size, the window size and the size of the document.
How pageviews are sent
Section titled How pageviews are sentTwo instructions can be responsible for the launch of a pageview.
Natural pageview
Section titled Natural pageviewA pageview is automatically and compulsorily sent when the main tag has loaded.
It is not possible to prevent this sending but it is possible to modify the sent URL. Note that the URL which is sent does not include the hash (meaning the elements appearing after the #
).
Artificial pageview
Section titled Artificial pageviewA JavaScript instruction can be executed to send an artificial pageview via the trackPageview
command. Use this command when the page changes without provoking a full reload, meaning a new loading of the main tag:
- AJAX loading,
- Popin opening,
- Tabs changing,…
Sending a natural pageview
Section titled Sending a natural pageviewYou just have to load the main tag.
Learn more about the main tag…
Sending an artificial pageview
Section titled Sending an artificial pageviewModifying the sent URL
Section titled Modifying the sent URLContentsquare provides commands to modify the URL to be sent automatically by the Tag.
Use cases include passing information after the ’#’ sign, or removing Personal Data.
Modifying the path
Section titled Modifying the pathTo override the path, use the setPath
command:
The domain will be automatically added before, and the query after.
Recommendations and limits
Section titled Recommendations and limits-
The value passed should be 255 characters maximum.
-
Do not add ”#”, since fragments are considered to be anchors and all that comes after will be erased in the Contentsquare pipeline.
-
Don’t use this command to push query parameters. If you do and the initial URL already has query parameters, you will end up having a badly formed URL:
- Initial URL:
https://www.domain.com/path?initial=1
- Sent URL:
https://www.domain.com/overridenPath?overriden=0?initial=1
- Initial URL:
Example
Section titled ExampleLet’s take the example of a Single Page Application that is using the fragment instead of the path to define the page identifier:
- The initial URL of the page is:
https://www.domain.com/en#dynamic-app-path/in-the-fragment?query=param
- The URL inserted in the Contentsquare database would be:
https://www.domain.com/en
- To fix that, we need to replace the
#
by something else (/__
):window._uxa.push(['setPath', window.location.pathname + window.location.hash.replace('#','/__')]);
- Resulting URL:
https://www.domain.com/en/__dynamic-app-path/in-the-fragment?query=param
Modifying the query parameters
Section titled Modifying the query parametersTo override the query parameters, use the following command:
The domain and path will be automatically added before.
Recommendations and limits
Section titled Recommendations and limits- The value passed should be 255 characters maximum.
- Do not add ”#”, since fragments are considered to be anchors and all that comes after will be erased in the Contentsquare pipeline.
Example
Section titled ExampleLet’s take the example of a page that could be loaded with a popin displayed and we want to be able to identify it:
- The initial URL of the page is:
https://www.domain.com/mypage?existingQueryParam=all
- Using
setQuery
:window._uxa.push(['setQuery', window.location.search + '&cookies-popin=true']);
- Resulting URL:
https://www.domain.com/mypage?existingQueryParam=all&cookies-popin=true
Verifying the sending of pageviews
Section titled Verifying the sending of pageviewsThe Contentsquare Tracking Setup Assistant Chrome Extension ↗ will display each pageview sent with its URL and Custom vars.
Checking the requests
Section titled Checking the requestsTo check the actual request that is sent, follow GET requests sent to //c.contentsquare.net/pageview
, with these query parameters:
Name | Description | Type |
---|---|---|
url | Page URL | String |
cvarp | Custom vars defined for this page | JSON — optional |
pid | Project ID | Integer |
r | A random digit to avoid request caching | Integer |
uu | Unique user ID | String |
pn | Page number (each pageview increments of 1) | Integer |
lv | Last visit | Timestamp |
hd | Hit Date | Timestamp |
lhd | Last hit date | Timestamp |
sn | Session number | Integer |
re | Collection | 1 (standard), 3 (replay) or 5 (triggered replay) |
dw | Document width | Integer |
dh | Document height | Integer |
la | User’s browser language | String |
dr | Previous page URL (referrer) | String |
sw | Screen width | Integer |
sh | Screen height | Integer |
ww | Window width | Integer |
wh | Window height | Integer |
cvars | Session’s custom vars | JSON — optional |
cvaru | User’s custom vars | JSON — optional |
v | UXA tag’s number of versions | String |
pvt | Pageview type | ”a” (artificial), “r” (renewal), or “n” (natural) |
ex | Indicates if the pageview can be included in a replay | SR (not included) or empty (can be included) |
uc | User Consent | 0 (Not required), 1 (Not expressed), 2 (Granted) or 3 (Withdrawn) |
uxt | Ongoing UXT tests, where required | JSON — optional |
uxtv | Testing tag version, where required | String — optional |