2020-10-20 00:31:54 +03:00
const languages = require ( './languages' )
const context = {
type : 'object' ,
additionalProperties : false ,
required : [
'event_id' ,
'user' ,
'version' ,
'created' ,
'path'
] ,
properties : {
// Required of all events
event _id : {
type : 'string' ,
description : 'The unique identifier of the event.' ,
format : 'uuid'
} ,
user : {
type : 'string' ,
description : 'The unique identifier of the current user performing the event. Please use randomly generated values or hashed values; we don\'t want to be able to look up in a database.' ,
format : 'uuid'
} ,
version : {
type : 'string' ,
description : 'The version of the event schema.' ,
pattern : '^\\d+(\\.\\d+)?(\\.\\d+)?$' // eslint-disable-line
} ,
created : {
type : 'string' ,
format : 'date-time' ,
description : 'The time we created the event; please reference UTC.'
} ,
// Content information
path : {
type : 'string' ,
description : 'The browser value of `location.pathname`.' ,
format : 'uri-reference'
} ,
2020-11-16 20:49:12 +03:00
hostname : {
type : 'string' ,
description : 'The browser value of `location.hostname.`' ,
format : 'uri-reference'
} ,
2020-10-20 00:31:54 +03:00
referrer : {
type : 'string' ,
description : 'The browser value of `document.referrer`.' ,
format : 'uri-reference'
} ,
search : {
type : 'string' ,
description : 'The browser value of `location.search`.'
} ,
href : {
type : 'string' ,
description : 'The browser value of `location.href`.' ,
format : 'uri'
} ,
site _language : {
type : 'string' ,
description : 'The language the user is viewing.' ,
enum : Object . keys ( languages )
} ,
// Device information
os : {
type : 'string' ,
description : 'The type of operating system the user is working with.' ,
enum : [ 'windows' , 'mac' , 'linux' , 'ios' , 'android' , 'other' ] ,
default : 'other'
} ,
os _version : {
type : 'string' ,
description : 'The version of the operating system the user is using.'
} ,
browser : {
type : 'string' ,
description : 'The type of browser the user is browsing with.' ,
enum : [ 'chrome' , 'safari' , 'firefox' , 'edge' , 'ie' , 'other' ] ,
default : 'other'
} ,
browser _version : {
type : 'string' ,
description : 'The version of the browser the user is browsing with.'
} ,
viewport _width : {
type : 'number' ,
description : 'The viewport width, not the overall device size.' ,
minimum : 1
} ,
viewport _height : {
type : 'number' ,
description : 'The viewport height, not the overall device height.' ,
minimum : 1
} ,
// Location information
timezone : {
type : 'number' ,
description : 'The timezone the user is in, as `new Date().getTimezoneOffset() / -60`.'
} ,
user _language : {
type : 'string' ,
description : 'The browser value of `navigator.language`.'
}
}
}
const pageSchema = {
2020-09-27 15:10:11 +03:00
additionalProperties : false ,
required : [
'type' ,
2020-10-20 00:31:54 +03:00
'context'
2020-09-27 15:10:11 +03:00
] ,
properties : {
2020-10-20 00:31:54 +03:00
context ,
2020-09-27 15:10:11 +03:00
type : {
type : 'string' ,
2020-10-20 00:31:54 +03:00
pattern : '^page$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
page _render _duration : {
type : 'number' ,
description : 'How long the server took to render the page content, in seconds.' ,
minimum : 0.001
}
}
}
const exitSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'exit_page_id'
] ,
properties : {
context ,
type : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
pattern : '^exit$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
exit _page _id : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
format : 'uuid' ,
description : 'The value of the corresponding `page` event.'
// id of the "page" event
} ,
exit _first _paint : {
type : 'number' ,
minimum : 0.001 ,
description : 'The duration until `first-contentful-paint`, in seconds. Informs CSS performance.'
} ,
exit _dom _interactive : {
type : 'number' ,
minimum : 0.001 ,
description : 'The duration until `PerformanceNavigationTiming.domInteractive`, in seconds. Informs JavaScript loading performance.'
} ,
exit _dom _complete : {
type : 'number' ,
minimum : 0.001 ,
description : 'The duration until `PerformanceNavigationTiming.domComplete`, in seconds. Informs JavaScript execution performance.'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
exit _visit _duration : {
type : 'number' ,
minimum : 0.001 ,
description : 'The duration of exit.timestamp - page.timestamp, in seconds. Informs bounce rate.'
} ,
exit _scroll _length : {
type : 'number' ,
minimum : 0 ,
maximum : 1 ,
description : 'The percentage of how far the user scrolled on the page.'
}
}
}
const linkSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'link_url'
] ,
properties : {
context ,
type : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
pattern : '^link$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
link _url : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
format : 'uri' ,
description : 'The href of the anchor tag the user clicked, or the page or object they directed their browser to.'
}
}
}
const searchSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'search_query'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^search$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
search _query : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
description : 'The actual text content of the query string the user sent to the service.'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
search _context : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
description : 'Any additional search context, such as component searched.'
2020-09-27 15:10:11 +03:00
}
}
}
2020-10-20 00:31:54 +03:00
const navigateSchema = {
2020-09-27 15:10:11 +03:00
additionalProperties : false ,
required : [
'type' ,
2020-10-20 00:31:54 +03:00
'context'
2020-09-27 15:10:11 +03:00
] ,
properties : {
2020-10-20 00:31:54 +03:00
context ,
2020-09-27 15:10:11 +03:00
type : {
type : 'string' ,
2020-10-20 00:31:54 +03:00
pattern : '^navigate$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
navigate _label : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
description : 'An identifier for where the user is navigating.'
}
}
}
const surveySchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'survey_vote'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^survey$'
} ,
token : {
type : 'string' ,
description : 'A honeypot.' ,
maxLength : 0
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
survey _vote : {
type : 'boolean' ,
description : 'Whether the user found the page helpful.'
} ,
survey _comment : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
description : 'Any textual comments the user wanted to provide.'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
survey _email : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
format : 'email' ,
description : 'The user\'s email address, if the user provided and consented.'
}
}
}
const experimentSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'experiment_name' ,
'experiment_variation'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^experiment$'
2020-09-27 15:10:11 +03:00
} ,
2020-10-20 00:31:54 +03:00
experiment _name : {
2020-09-27 15:10:11 +03:00
type : 'string' ,
2020-10-20 00:31:54 +03:00
description : 'The test that this event is part of.'
} ,
experiment _variation : {
type : 'string' ,
enum : [ 'control' , 'treatment' ] ,
description : 'The variation this user we bucketed in, such as control or treatment.'
} ,
experiment _success : {
type : 'boolean' ,
default : true ,
description : 'Whether or not the user successfully performed the test goal.'
2020-09-27 15:10:11 +03:00
}
}
}
2020-10-23 19:31:58 +03:00
const redirectSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'redirect_from' ,
'redirect_to'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^redirect$'
} ,
redirect _from : {
type : 'string' ,
description : 'The requested href.' ,
format : 'uri-reference'
} ,
redirect _to : {
type : 'string' ,
description : 'The destination href of the redirect.' ,
format : 'uri-reference'
}
}
}
const clipboardSchema = {
additionalProperties : false ,
required : [
'type' ,
'context' ,
'clipboard_operation'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^clipboard$'
} ,
clipboard _operation : {
type : 'string' ,
description : 'Which clipboard operation the user is performing.' ,
enum : [ 'copy' , 'paste' , 'cut' ]
}
}
}
const printSchema = {
additionalProperties : false ,
required : [
'type' ,
'context'
] ,
properties : {
context ,
type : {
type : 'string' ,
pattern : '^print$'
}
}
}
2020-09-27 15:10:11 +03:00
module . exports = {
2020-10-20 00:31:54 +03:00
oneOf : [
pageSchema ,
exitSchema ,
linkSchema ,
searchSchema ,
navigateSchema ,
surveySchema ,
2020-10-23 19:31:58 +03:00
experimentSchema ,
redirectSchema ,
clipboardSchema ,
printSchema
2020-10-20 00:31:54 +03:00
]
2020-09-27 15:10:11 +03:00
}