Install Pushbroom
Pushbroom needs two pieces of HTML on your site: a script, and a <push-broom> element on each page you want to count.
Add the script
Copy the snippet from your site's card in Your sites. Paste it before the closing </body> tag on every page you want to measure:
<script async="" defer="" src="https://pushbroom.co/script.js" data-key="your-site-key"></script>The script is under two kilobytes. The async and defer attributes stop it from delaying the rest of your page.
data-key is your site's key. Pushbroom uses it only to verify the site, so it doesn't need to be kept secret.
Verify your site
Pushbroom records nothing for a site until it is verified. After the snippet is live on your homepage, select Verify on the site's card. Pushbroom loads your homepage and looks for the key.
If your homepage adds the script with JavaScript, the key isn't in the HTML that Pushbroom loads. Add a DNS TXT record to the site's hostname instead, then select Verify again:
| Type | Name | Value |
|---|---|---|
TXT | your site's hostname | pushbroom-verification=your-site-key |
The site's card shows the exact value to use.
Pushbroom files each page view under the origin of the page that sent it, so install the snippet on the site you added. A site added as https://example.com also records views from https://www.example.com, and the other way round. Other subdomains, such as https://blog.example.com, must be added as sites of their own.
Count a page
The script doesn't record anything on its own. It records one page view for each <push-broom> element on the page:
<push-broom url="/pricing"></push-broom>The <push-broom> element accepts these attributes:
| Attribute | Description |
|---|---|
url | The path to record the view under, starting with /. Pushbroom adds your site's origin. |
pb:* | Extra values to record with the view. See Custom data. |
Set url on every element. A view without it is recorded without a page.
Elements that are added to the page after it loads are counted too.
Record a pattern instead of a path
Pushbroom records the url value exactly as you write it. It doesn't read the address in the browser. To keep something out of your data, such as a user ID in a path, write a pattern instead:
<push-broom url="/users/:id"></push-broom>Every page that uses this value is counted as the same page.
Single-page apps
When your router changes pages, update the element's url attribute. Each new value records a new page view. Other changes to the element or the page don't, so a re-render isn't counted twice.
Each element records its own views, so use one element per page.
Let visitors opt out
The script records nothing for visitors whose browser sends Global Privacy Control. It also skips browsers that identify themselves as bots, crawlers or link previews.
To offer an opt-out on your own site, call these from your page:
| Call | Effect |
|---|---|
window.pushbroom?.block() | Stops recording in this browser. |
window.pushbroom?.unblock() | Starts recording again. |
window.pushbroom?.blocked | true if this browser is opted out, either by block() or by Global Privacy Control. |
block() saves a flag in the browser's local storage for your site. While the flag is set, the script sends no page views or events. On later page loads, it doesn't request a visit identifier either.
Read the source
The file at /script.js is minified. The full source is published at pushbroom.co/script.src.js.