Releases: Swetrix/swetrix-js
v3.0.3
Changelog:
- Fix types for the v3.0.2 release.
For full v3 release notes see https://github.com/Swetrix/swetrix-js/releases/tag/v3.0.0
v3.0.2
Changelog:
trackViews
callback - updated return type fromIPageViewPayload
toPartial<IPageViewPayload>
For full v3 release notes see https://github.com/Swetrix/swetrix-js/releases/tag/v3.0.0
v3.0.1
Changelog:
- Fixed
IPageViewPayload
pg type
For full v3 release notes see https://github.com/Swetrix/swetrix-js/releases/tag/v3.0.0
v3.0.0
Changelog:
- [BREAKING] Removed the
noUserFlow
,doNotAnonymise
,ignore
andnoHeartbeat
parameters for thetrackViews
function. - [BREAKING] The
debug
parameter for theinit
function has been removed. Instead,devMode
is introduced. The only difference betweendebug
anddevMode
is that messages are no longer printed to the console. - Introducing new
trackViews
optional parameter -callback
. The callback is supposed to replaceignore
parameter and give you more control over what data is tracked.
The callback accepts the following object as it's only parameter:
interface IPageViewPayload {
lc: string | undefined
tz: string | undefined
ref: string | undefined
so: string | undefined
me: string | undefined
ca: string | undefined
pg: string
prev: string | null | undefined
}
The callback should return one of the following:
true
- to send the pageview event as-is.false
- to prevent sending the payload.- An IPageViewPayload-like
object
- the object should contain the edited fields that will be assigned to the payload. For example, if yourpg
has some sensitive information (like/account/54345345
), you can replace it with/account/redacted
and return it as a callback result to be sent to the API. Note that the Swetrix script will append the callback result to an already existing payload, so if you're only returningpg
- all the other parameters will be sent as is, if you'd like to overwrite them - you'll need to explicitly return them in the callback object.
Migration guide:
No changes in Swetrix config are needed unless you've been using the ignore
parameter in the trackViews
function.
If you were using ignore
parameter in past - you may need to replace it with the callback
instead. Here's an example on how you can do that.
Before upgrading to that version of Swetrix, your setup may look like this:
Swetrix.trackViews({
ignore: [
/^\/users\/(?!new$)[^/]+$/i,
/^\/share/i,
'some-other-page',
],
heartbeatOnBackground: true,
// any other parameters
})
After upgrading, you'll need to replace ignore
with a callback
and here's an example on how you can do that:
const checkIgnore = (path, ignore = []) => {
for (let i = 0; i < ignore.length; ++i) {
if (ignore[i] === path) return true
if (ignore[i] instanceof RegExp && ignore[i].test(path)) return true
}
return false
}
const pathsToIgnore = [/^\/users\/(?!new$)[^/]+$/i, /^\/share/i, 'some-other-page']
Swetrix.trackViews({
callback: ({ pg, prev }) => {
const result = {
pg,
prev,
}
if (checkIgnore(pg, pathsToIgnore)) {
// or you can return any other value to ignore this page
// for example, returning null will display REDACTED for this page in your dashboard
// but instead you can return something like 'users/:id' to group all users pages together
result.pg = null
}
if (checkIgnore(prev, pathsToIgnore)) {
// same as above
result.prev = null
}
return result
},
heartbeatOnBackground: true,
})
v2.4.0
v2.3.1
v2.3.0 - the 5 September 2023 Release
Changelog:
- Added a
doNotAnonymise
parameter totrackViews
function. It allows to not send paths from ignore list to API. If set tofalse
, the page view information will be sent to the Swetrix API, but the page will be displayed as a 'Redacted page' in the dashboard. - Updated a few dependencies.
v2.2.1 - the 27 April 2023 Release
Changelog:
- Fixed a bug when
previous
page was sent without validating it withignore
parameter first.
v2.2.0 - the 26 April 2023 Release
Changelog:
- Added support for tracking user flow (by sending the previous page user was on to the server).
- Added
noUserFlow
boolean parameter toPageViewsOptions
. If you want to disable user flow tracking, just set this parameter totrue
. By default it'sfalse
which means that the user flow tracking is enabled.
v2.1.0 - the 9 February 2023 Release
Changelog:
- Sending additional data to the API along with the custom event.
- Updated dependencies.