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: v0.3.5
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: 450a9d10dd1b18708c2a919fc74c7a432fb2c3cc
Choose a head ref
  • 5 commits
  • 5 files changed
  • 4 contributors

Commits on Apr 2, 2022

  1. fix(request): accept number and boolean as event props

    According to Plausible docs, event props can be strings, numbers or
    booleans: https://plausible.io/docs/custom-event-goals#using-custom-props
    ouuan committed Apr 2, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    ouuan Yufan You
    Copy the full SHA
    d6461f9 View commit details

Commits on Apr 4, 2022

  1. Merge pull request #27 from ouuan/event-props-number-boolean

    fix(request): accept number and boolean as event props
    ukutaht authored Apr 4, 2022

    Verified

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

Commits on May 13, 2022

  1. Don't access localStorage if it is not available

    Some browsers completely remove the localStorage key when certain settings are enabled (for example: "disable all cookies"). This adds an extra check to ensure localStorage is available before accessing it.
    Windvis committed May 13, 2022
    Copy the full SHA
    879e8bc View commit details

Commits on Jun 6, 2022

  1. Merge pull request #31 from Windvis/fix/local-storage-access-check

    Don't access localStorage if it is not available
    ukutaht authored Jun 6, 2022

    Verified

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

    ukutaht committed Jun 6, 2022
    Copy the full SHA
    450a9d1 View commit details
Showing with 31 additions and 3 deletions.
  1. +8 −1 CHANGELOG.md
  2. +1 −1 package.json
  3. +14 −0 src/lib/request.spec.ts
  4. +6 −1 src/lib/request.ts
  5. +2 −0 src/lib/tracker.spec.ts
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.3.4](https://github.com/Maronato/plausible-tracker/compare/v0.3.4...v0.3.5) (2022-01-25)
### [0.3.6](https://github.com/Maronato/plausible-tracker/compare/v0.3.5...v0.3.6) (2022-06-06)

### Bug Fixes

* **tracker:** Don't access localStorage if it is not available #31 ([#31](https://github.com/plausible/plausible-tracker/pull/31))
* **tracker:** Accept number and boolean as event props ([#27](https://github.com/plausible/plausible-tracker/pull/27))

### [0.3.5](https://github.com/Maronato/plausible-tracker/compare/v0.3.4...v0.3.5) (2022-01-25)

### Changes

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.5",
"version": "0.3.6",
"description": "Official frontend tracker to interact with Plausible Analytics",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
14 changes: 14 additions & 0 deletions src/lib/request.spec.ts
Original file line number Diff line number Diff line change
@@ -123,6 +123,20 @@ describe('sendEvent', () => {

window.localStorage.removeItem('plausible_ignore');
});
test('does not throw an error if localStorage is not available', () => {
const localStorage = window.localStorage;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window['localStorage'];

expect(xmr).not.toHaveBeenCalled();
sendEvent('myEvent', defaultData);
expect(xmr).toHaveBeenCalled();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.localStorage = localStorage;
});
test('calls callback', () => {
expect(xmr).not.toHaveBeenCalled();
const callback = jest.fn();
7 changes: 6 additions & 1 deletion src/lib/request.ts
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ export type EventOptions = {
/**
* Properties to be bound to the event.
*/
readonly props?: { readonly [propName: string]: string };
readonly props?: { readonly [propName: string]: string | number | boolean };
};

/**
@@ -48,8 +48,13 @@ export function sendEvent(
);
}

const canAccessLocalStorage =
typeof window.localStorage?.getItem === 'function';

const shouldIgnoreCurrentBrowser =
canAccessLocalStorage &&
localStorage.getItem('plausible_ignore') === 'true';

if (shouldIgnoreCurrentBrowser) {
return console.warn(
'[Plausible] Ignoring event because "plausible_ignore" is set to "true" in localStorage'
2 changes: 2 additions & 0 deletions src/lib/tracker.spec.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,8 @@ describe('tracker', () => {
props: {
variation1: 'A',
variation2: 'B',
variation3: 1,
variation4: true,
},
});