> For the complete documentation index, see [llms.txt](https://documentation.pushly.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.pushly.com/integration/web-push/sdk/activity-tracking.md).

# Activity Tracking

{% hint style="danger" %}

## Not Required for Most Partners

This feature is only needed for partners who either:

* use SRI (Subresource Integrity) and cannot allow the Pushly loader to fetch updated SDK assets automatically, or
* self-host the Pushly SDK (serve it from their own servers/CDN)
  {% endhint %}

### Overview

The Pushly SDK supports sending “content context” signals from your site to Pushly. These signals let Pushly build cohorts based on what a subscriber has viewed, how often they viewed it, and how recently.

This powers segmentation like:

* Subscribers who visited any page tagged “Astrology” at least 4 times in the last 30 days
* Subscribers who visited content tagged “Elections” in the last 7 days
* Subscribers who visited multiple categories (ex: “sports” AND “politics”) over the last 14 days

These tags are defined by you at runtime and should map cleanly to your content taxonomy (categories, sections, keywords, authors, topics, etc.).

### Prerequisites

1. The standard Pushly integration snippet must already be installed and running on the page.
2. `window.PushlySDK` must be available before you call these methods.

If you call before the SDK is ready, queueing still works (see usage below), but you must ensure the integration snippet has executed first.

### When to call

Call this after you’ve determined the page’s tags (usually once per page view):

* Traditional multi-page sites: call once on page load after tags are known.
* SPAs / client-side routing: call on every route change when the viewed content changes.

Avoid calling repeatedly for the same view (ex: on scroll, on timers, or in re-render loops).

***

### Method: `page_tag_visit`

Records that the current subscriber viewed a page associated with one or more tags.

#### Signature

```js
window.PushlySDK.push(['page_tag_visit', [tags]]);
```

#### Parameters

* `tags` (Array of strings) – required\
  A list of 1+ tags to associate with this page view.

#### Tag rules / recommendations

* Use stable, human-readable slugs (recommended): `["astrology", "sports", "politics"]`
* Keep tags reasonably short (avoid dumping entire keyword lists)
* Maximum of 20 tags per page view. Any tags beyond the first 20 will be ignored.
* Do not include PII (no emails, names of private individuals, user IDs, etc.)

### Examples

#### Basic example

```js
window.PushlySDK.push(['page_tag_visit', ['sports', 'politics', 'custom_tag_1']]);
```

#### Example with runtime tags from the page

```js
var tags = window.pageTags || []; // however your site exposes tags
if (tags.length) {
  window.PushlySDK.push(['page_tag_visit', tags]);
}
```

#### SPA example (route changes)

```js
function trackCurrentRouteTags() {
  var tags = getTagsForCurrentRoute(); // your implementation
  if (tags && tags.length) {
    window.PushlySDK.push(['page_tag_visit', tags]);
  }
}

// Call on initial load
trackCurrentRouteTags();

// Call on route changes
window.addEventListener('popstate', trackCurrentRouteTags);
```

(Use your router’s hook/event if you have one; `popstate` is just the generic baseline.)

### Notes and common pitfalls

* Order doesn’t matter: `['sports','politics']` is the same as `['politics','sports']`
* Dedupe your tags before sending if your CMS can emit duplicates.
* Don’t call it before the Pushly snippet runs. If you inline this in the `<head>`, it can fire too early. Place it after the Pushly snippet or after your tag data is available.

***

### Troubleshooting

If cohorts don’t populate as expected:

1. Confirm the Pushly base snippet is present and loading successfully (no blocked requests, no JS errors).
2. Confirm `window.PushlySDK` exists and that calls are being queued/executed.
3. Confirm the tags being passed are strings (not objects) and look like what you expect.
4. Confirm you’re sending tags on every relevant page view (especially for SPAs).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.pushly.com/integration/web-push/sdk/activity-tracking.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
