Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: plausible/plausible-tracker
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 294405cafc934ee666c1a295a5b2fd8737993ce2
Choose a base ref
...
head repository: plausible/plausible-tracker
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab75723ad10660cbaee3718d1b0a670e2dfd717d
Choose a head ref
  • 5 commits
  • 5 files changed
  • 4 contributors

Commits on Aug 31, 2022

  1. Remove david-dm from README

    The `david-dm.org` website is down for 3 months, and the project `alanshaw/david` is not actively maintained anymore. `david-dm.org` should be considered dead, thus badges should be removed from README.
    renbaoshuo authored Aug 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f1fda00 View commit details

Commits on Sep 1, 2022

  1. Merge pull request #46 from renbaoshuo/patch-1

    Remove david-dm from README
    ukutaht authored Sep 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c0b87d9 View commit details

Commits on May 22, 2024

  1. Make tracking work with site verification

    We now need to instrument the `window` object with
    the `plausible()` function and extend its signature
    to provide request status in the callback options.
    aerosol committed May 22, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    81b440e View commit details

Commits on May 27, 2024

  1. Merge pull request #65 from plausible/site-verification-extension

    Make tracking work with site verification
    ukutaht authored May 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2dc3dcf View commit details
  2. Bump version

    ukutaht committed May 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab75723 View commit details
Showing with 6,294 additions and 6,457 deletions.
  1. +0 −4 README.md
  2. +1 −1 package.json
  3. +6 −2 src/lib/request.ts
  4. +16 −0 src/lib/tracker.ts
  5. +6,271 −6,450 yarn.lock
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,10 +4,6 @@

[![Build Status](https://travis-ci.com/plausible/plausible-tracker.svg?branch=master)](https://travis-ci.com/plausible/plausible-tracker) [![codecov](https://codecov.io/gh/plausible/plausible-tracker/branch/master/graph/badge.svg)](https://codecov.io/gh/plausible/plausible-tracker) [![Netlify Status](https://api.netlify.com/api/v1/badges/d29c0d49-6ba4-412b-af90-d21865eb40f2/deploy-status)](https://app.netlify.com/sites/plausible-tracker/deploys)


[![dependencies Status](https://david-dm.org/plausible/plausible-tracker/status.svg)](https://david-dm.org/maronato/plausible-tracker) [![devDependencies Status](https://david-dm.org/plausible/plausible-tracker/dev-status.svg)](https://david-dm.org/maronato/plausible-tracker?type=dev)


Frontend library to interact with [Plausible Analytics](https://plausible.io/).

- [Plausible Analytics Tracker](#plausible-analytics-tracker)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plausible-tracker",
"version": "0.3.8",
"version": "0.3.9",
"description": "Official frontend tracker to interact with Plausible Analytics",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
8 changes: 6 additions & 2 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
@@ -13,12 +13,16 @@ type EventPayload = {
readonly p?: string;
};

type CallbackArgs = {
readonly status: number;
};

// eslint-disable-next-line functional/no-mixed-type
export type EventOptions = {
/**
* Callback called when the event is successfully sent.
*/
readonly callback?: () => void;
readonly callback?: (args: CallbackArgs) => void;
/**
* Properties to be bound to the event.
*/
@@ -76,7 +80,7 @@ export function sendEvent(
req.onreadystatechange = () => {
if (req.readyState !== 4) return;
if (options && options.callback) {
options.callback();
options.callback({ status: req.status });
}
};
}
16 changes: 16 additions & 0 deletions src/lib/tracker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { EventOptions, sendEvent } from './request';

declare global {
// eslint-disable-next-line functional/prefer-type-literal
interface Window {
// eslint-disable-next-line functional/prefer-readonly-type
plausible: TrackEvent;
}
}

/**
* Options used when initializing the tracker.
*/
@@ -207,6 +215,7 @@ type EnableAutoOutboundTracking = (
*
* @param defaults - Default event parameters that will be applied to all requests.
*/

export default function Plausible(
defaults?: PlausibleInitOptions
): {
@@ -215,6 +224,11 @@ export default function Plausible(
readonly enableAutoPageviews: EnableAutoPageviews;
readonly enableAutoOutboundTracking: EnableAutoOutboundTracking;
} {
const modifyWindow = () => {
// eslint-disable-next-line functional/immutable-data
window.plausible = trackEvent;
};

const getConfig = (): Required<PlausibleOptions> => ({
hashMode: false,
trackLocalhost: false,
@@ -230,6 +244,8 @@ export default function Plausible(
sendEvent(eventName, { ...getConfig(), ...eventData }, options);
};

modifyWindow();

const trackPageview: TrackPageview = (eventData, options) => {
trackEvent('pageview', options, eventData);
};
Loading