npm install @putdotio/pas-jsimport createPasClient from "@putdotio/pas-js";
const pas = createPasClient();
pas.identify({
id: "42",
hash: "signed-user-hash",
properties: {
plan: "pro",
},
});
pas.track("transfer_completed", {
transfer_id: 123,
});The client keeps an anonymous identifier in a browser cookie and sends identity, event, and page-view payloads to PAS:
pas.alias({ id: "42", hash: "signed-user-hash" });
pas.pageView();pageView sends the page's origin and path, its utm_source, utm_medium,
and utm_campaign values, and only the origin of the referrer. Nothing else
from either URL is sent, so search terms in them stay out of PAS. When the path
itself carries something PAS must not store, such as a username or an invite
code, pass the path to send instead:
pas.pageView({ path: "/files/user/FILTERED" });Requests that fail with a server or network error are stored in a cookie and
replayed on the next initialization. pas.clear() starts a new anonymous
identity.
When the visitor turns analytics off, dispose the client, then remove its
pas_js_user and pas_js_retry_queue cookies from the configured cache domain
(.put.io by default). Disposing aborts requests in flight, so none reaches
the retry queue, and later calls send nothing and write no cookies:
import Cookies from "js-cookie";
pas.dispose();
Cookies.remove("pas_js_user", { domain: ".put.io" });
Cookies.remove("pas_js_retry_queue", { domain: ".put.io" });This project is available under the MIT License.
