mirror of
https://github.com/plausible/analytics.git
synced 2024-12-21 08:31:29 +03:00
ba19f9530e
* copy relevant files from b2ace16540
* make it work and set site.funnels to empty list
* make Behaviours a functional component
* add UI for a setup hint and always display conversions by default
* cherry-pick migration commit
* update site schema with new fields
* backend: implement disable-feature action
* switch between tabs in the behaviors section
Introduces template components to build props and funnels on. Both
only show a setup notice atm, and both are behind feature flags.
* extend API for disabling props and funnels
* render feature setup note directly from the Behaviours component
* fix UI behavior when features are hidden
* update setup notices
* add conversions feature switch to Site Settings > Goals
* mix format
* remove IO.inspect
* change setup notice - use buttons + popup confirmation
* optimize for light mode
* restrict access to setup notices
* some styling improvements
* allow super-admins to enable/disable features
* only show conversions (last 30min) in realtime mode
* use shorter display names for tabs
* optimize for mobile screens
* note about sending custom events
* changelog update + fix CI
* change HTTP verb for the disable-feature action
* change UI label for show/hide goals
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
import {formatISO} from './util/date'
|
|
|
|
let abortController = new AbortController()
|
|
let SHARED_LINK_AUTH = null
|
|
|
|
class ApiError extends Error {
|
|
constructor(message, payload) {
|
|
super(message)
|
|
this.name = "ApiError"
|
|
this.payload = payload
|
|
}
|
|
}
|
|
|
|
function serialize(obj) {
|
|
var str = [];
|
|
for (var p in obj)
|
|
/* eslint-disable-next-line no-prototype-builtins */
|
|
if (obj.hasOwnProperty(p)) {
|
|
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
|
}
|
|
return str.join("&");
|
|
}
|
|
|
|
export function setSharedLinkAuth(auth) {
|
|
SHARED_LINK_AUTH = auth
|
|
}
|
|
|
|
export function cancelAll() {
|
|
abortController.abort()
|
|
abortController = new AbortController()
|
|
}
|
|
|
|
function serializeFilters(filters) {
|
|
const cleaned = {}
|
|
Object.entries(filters).forEach(([key, val]) => val ? cleaned[key] = val : null);
|
|
return JSON.stringify(cleaned)
|
|
}
|
|
|
|
export function serializeQuery(query, extraQuery=[]) {
|
|
const queryObj = {}
|
|
if (query.period) { queryObj.period = query.period }
|
|
if (query.date) { queryObj.date = formatISO(query.date) }
|
|
if (query.from) { queryObj.from = formatISO(query.from) }
|
|
if (query.to) { queryObj.to = formatISO(query.to) }
|
|
if (query.filters) { queryObj.filters = serializeFilters(query.filters) }
|
|
if (query.with_imported) { queryObj.with_imported = query.with_imported }
|
|
if (SHARED_LINK_AUTH) { queryObj.auth = SHARED_LINK_AUTH }
|
|
|
|
if (query.comparison) {
|
|
queryObj.comparison = query.comparison
|
|
queryObj.compare_from = query.compare_from ? formatISO(query.compare_from) : undefined
|
|
queryObj.compare_to = query.compare_to ? formatISO(query.compare_to) : undefined
|
|
queryObj.match_day_of_week = query.match_day_of_week
|
|
}
|
|
|
|
Object.assign(queryObj, ...extraQuery)
|
|
|
|
return '?' + serialize(queryObj)
|
|
}
|
|
|
|
export function get(url, query={}, ...extraQuery) {
|
|
const headers = SHARED_LINK_AUTH ? {'X-Shared-Link-Auth': SHARED_LINK_AUTH} : {}
|
|
url = url + serializeQuery(query, extraQuery)
|
|
return fetch(url, {signal: abortController.signal, headers: headers})
|
|
.then( response => {
|
|
if (!response.ok) {
|
|
return response.json().then((msg) => {
|
|
throw new ApiError(msg.error, msg)
|
|
})
|
|
}
|
|
return response.json()
|
|
})
|
|
}
|
|
|
|
export function put(url, body) {
|
|
return fetch(url, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body)
|
|
})
|
|
}
|