feat: analytics modules backend + admin panel
This commit is contained in:
parent
b34aa5bab4
commit
537551874b
@ -50,6 +50,9 @@
|
||||
template(v-if='hasPermission(`manage:system`)')
|
||||
v-divider.my-2
|
||||
v-subheader.pl-4 {{ $t('admin:nav.modules') }}
|
||||
v-list-tile(to='/analytics')
|
||||
v-list-tile-avatar: v-icon timeline
|
||||
v-list-tile-title {{ $t('admin:analytics.title') }}
|
||||
v-list-tile(to='/auth')
|
||||
v-list-tile-avatar: v-icon lock_outline
|
||||
v-list-tile-title {{ $t('admin:auth.title') }}
|
||||
@ -143,6 +146,7 @@ const router = new VueRouter({
|
||||
{ path: '/groups/:id', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-groups-edit.vue') },
|
||||
{ path: '/users', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-users.vue') },
|
||||
{ path: '/users/:id', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-users-edit.vue') },
|
||||
{ path: '/analytics', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-analytics.vue') },
|
||||
{ path: '/auth', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-auth.vue') },
|
||||
{ path: '/rendering', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-rendering.vue') },
|
||||
{ path: '/editor', component: () => import(/* webpackChunkName: "admin" */ './admin/admin-editor.vue') },
|
||||
|
178
client/components/admin/admin-analytics.vue
Normal file
178
client/components/admin/admin-analytics.vue
Normal file
@ -0,0 +1,178 @@
|
||||
<template lang='pug'>
|
||||
v-container(fluid, grid-list-lg)
|
||||
v-layout(row, wrap)
|
||||
v-flex(xs12)
|
||||
.admin-header
|
||||
img.animated.fadeInUp(src='/svg/icon-line-chart.svg', alt='Analytics', style='width: 80px;')
|
||||
.admin-header-title
|
||||
.headline.primary--text.animated.fadeInLeft {{ $t('admin:analytics.title') }}
|
||||
.subheading.grey--text.animated.fadeInLeft.wait-p4s {{ $t('admin:analytics.subtitle') }}
|
||||
v-spacer
|
||||
v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', @click='refresh', large)
|
||||
v-icon refresh
|
||||
v-btn.animated.fadeInDown(color='success', @click='save', depressed, large)
|
||||
v-icon(left) check
|
||||
span {{$t('common:actions.apply')}}
|
||||
|
||||
v-flex(lg3, xs12)
|
||||
v-card.animated.fadeInUp
|
||||
v-toolbar(flat, color='primary', dark, dense)
|
||||
.subheading {{$t('admin:analytics.providers')}}
|
||||
v-list(two-line, dense).py-0
|
||||
template(v-for='(str, idx) in providers')
|
||||
v-list-tile(:key='str.key', @click='selectedProvider = str.key', :disabled='!str.isAvailable')
|
||||
v-list-tile-avatar
|
||||
v-icon(color='grey', v-if='!str.isAvailable') indeterminate_check_box
|
||||
v-icon(color='primary', v-else-if='str.isEnabled', v-ripple, @click='str.isEnabled = false') check_box
|
||||
v-icon(color='grey', v-else, v-ripple, @click='str.isEnabled = true') check_box_outline_blank
|
||||
v-list-tile-content
|
||||
v-list-tile-title.body-2(:class='!str.isAvailable ? `grey--text` : (selectedProvider === str.key ? `primary--text` : ``)') {{ str.title }}
|
||||
v-list-tile-sub-title.caption(:class='!str.isAvailable ? `grey--text text--lighten-1` : (selectedProvider === str.key ? `blue--text ` : ``)') {{ str.description }}
|
||||
v-list-tile-avatar(v-if='selectedProvider === str.key')
|
||||
v-icon.animated.fadeInLeft(color='primary') arrow_forward_ios
|
||||
v-divider(v-if='idx < providers.length - 1')
|
||||
|
||||
v-flex(xs12, lg9)
|
||||
|
||||
v-card.wiki-form.animated.fadeInUp.wait-p2s
|
||||
v-toolbar(color='primary', dense, flat, dark)
|
||||
.subheading {{provider.title}}
|
||||
v-card-text
|
||||
v-form
|
||||
.analytic-provider-logo
|
||||
img(:src='provider.logo', :alt='provider.title')
|
||||
.caption.pt-3 {{provider.description}}
|
||||
.caption.pb-3: a(:href='provider.website') {{provider.website}}
|
||||
v-divider.mt-3
|
||||
v-subheader.pl-0 {{$t('admin:analytics.providerConfiguration')}}
|
||||
.body-1.ml-3(v-if='!provider.config || provider.config.length < 1'): em {{$t('admin:analytics.providerNoConfiguration')}}
|
||||
template(v-else, v-for='cfg in provider.config')
|
||||
v-select(
|
||||
v-if='cfg.value.type === "string" && cfg.value.enum'
|
||||
outline
|
||||
background-color='grey lighten-2'
|
||||
:items='cfg.value.enum'
|
||||
:key='cfg.key'
|
||||
:label='cfg.value.title'
|
||||
v-model='cfg.value.value'
|
||||
prepend-icon='settings_applications'
|
||||
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
||||
persistent-hint
|
||||
:class='cfg.value.hint ? "mb-2" : ""'
|
||||
)
|
||||
v-switch.mb-3(
|
||||
v-else-if='cfg.value.type === "boolean"'
|
||||
:key='cfg.key'
|
||||
:label='cfg.value.title'
|
||||
v-model='cfg.value.value'
|
||||
color='primary'
|
||||
prepend-icon='settings_applications'
|
||||
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
||||
persistent-hint
|
||||
)
|
||||
v-text-field(
|
||||
v-else
|
||||
outline
|
||||
background-color='grey lighten-2'
|
||||
:key='cfg.key'
|
||||
:label='cfg.value.title'
|
||||
v-model='cfg.value.value'
|
||||
prepend-icon='settings_applications'
|
||||
:hint='cfg.value.hint ? cfg.value.hint : ""'
|
||||
persistent-hint
|
||||
:class='cfg.value.hint ? "mb-2" : ""'
|
||||
)
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import _ from 'lodash'
|
||||
|
||||
import providersQuery from 'gql/admin/analytics/analytics-query-providers.gql'
|
||||
import providersSaveMutation from 'gql/admin/analytics/analytics-mutation-save-providers.gql'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
providers: [],
|
||||
selectedProvider: '',
|
||||
provider: {}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
selectedProvider(newValue, oldValue) {
|
||||
this.provider = _.find(this.providers, ['key', newValue]) || {}
|
||||
},
|
||||
providers(newValue, oldValue) {
|
||||
this.selectedProvider = 'google'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async refresh() {
|
||||
await this.$apollo.queries.providers.refetch()
|
||||
this.$store.commit('showNotification', {
|
||||
message: this.$t('admin:analytics.refreshSuccess'),
|
||||
style: 'success',
|
||||
icon: 'cached'
|
||||
})
|
||||
},
|
||||
async save() {
|
||||
this.$store.commit(`loadingStart`, 'admin-analytics-saveproviders')
|
||||
try {
|
||||
await this.$apollo.mutate({
|
||||
mutation: providersSaveMutation,
|
||||
variables: {
|
||||
providers: this.providers.map(str => _.pick(str, [
|
||||
'isEnabled',
|
||||
'key',
|
||||
'config'
|
||||
])).map(str => ({...str, config: str.config.map(cfg => ({...cfg, value: JSON.stringify({ v: cfg.value.value })}))}))
|
||||
}
|
||||
})
|
||||
this.$store.commit('showNotification', {
|
||||
message: this.$t('admin:analytics.saveSuccess'),
|
||||
style: 'success',
|
||||
icon: 'check'
|
||||
})
|
||||
} catch (err) {
|
||||
this.$store.commit('pushGraphError', err)
|
||||
}
|
||||
this.$store.commit(`loadingStop`, 'admin-analytics-saveproviders')
|
||||
}
|
||||
},
|
||||
apollo: {
|
||||
providers: {
|
||||
query: providersQuery,
|
||||
fetchPolicy: 'network-only',
|
||||
update: (data) => _.cloneDeep(data.analytics.providers).map(str => ({
|
||||
...str,
|
||||
config: _.sortBy(str.config.map(cfg => ({
|
||||
...cfg,
|
||||
value: JSON.parse(cfg.value)
|
||||
})), [t => t.value.order])
|
||||
})),
|
||||
watchLoading (isLoading) {
|
||||
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-analytics-refresh')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
|
||||
.analytic-provider-logo {
|
||||
width: 250px;
|
||||
height: 85px;
|
||||
float:right;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 50px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
@ -99,36 +99,6 @@
|
||||
v-spacer
|
||||
v-chip(label, color='white', small).primary--text coming soon
|
||||
v-card-text
|
||||
v-switch(
|
||||
label='Analytics'
|
||||
color='primary'
|
||||
v-model='config.featureAnalytics'
|
||||
persistent-hint
|
||||
hint='Enable site analytics using service provider.'
|
||||
disabled
|
||||
)
|
||||
v-select.mt-3(
|
||||
outline
|
||||
label='Analytics Service Provider'
|
||||
:items='analyticsServices'
|
||||
v-model='config.analyticsService'
|
||||
prepend-icon='subdirectory_arrow_right'
|
||||
persistent-hint
|
||||
hint='Automatically add tracking code for services like Google Analytics.'
|
||||
disabled
|
||||
)
|
||||
v-text-field.mt-2(
|
||||
v-if='config.analyticsService !== ``'
|
||||
outline
|
||||
label='Property Tracking ID'
|
||||
:counter='255'
|
||||
v-model='config.analyticsId'
|
||||
prepend-icon='timeline'
|
||||
persistent-hint
|
||||
hint='A unique identifier provided by your analytics service provider.'
|
||||
)
|
||||
|
||||
v-divider.mt-3
|
||||
v-switch(
|
||||
label='Asset Image Optimization'
|
||||
color='primary'
|
||||
@ -191,7 +161,7 @@ export default {
|
||||
return {
|
||||
analyticsServices: [
|
||||
{ text: 'None', value: '' },
|
||||
{ text: 'Elasticsearch APM', value: 'elk' },
|
||||
{ text: 'Elasticsearch APM RUM', value: 'elk' },
|
||||
{ text: 'Google Analytics', value: 'ga' },
|
||||
{ text: 'Google Tag Manager', value: 'gtm' }
|
||||
],
|
||||
|
@ -166,7 +166,7 @@
|
||||
i18next.caption.mt-3(path='admin:storage.syncScheduleCurrent', tag='div')
|
||||
strong(place='schedule') {{getDefaultSchedule(target.syncInterval)}}
|
||||
i18next.caption(path='admin:storage.syncScheduleDefault', tag='div')
|
||||
strong {{getDefaultSchedule(target.syncIntervalDefault)}}
|
||||
strong(place='schedule') {{getDefaultSchedule(target.syncIntervalDefault)}}
|
||||
|
||||
template(v-if='target.actions && target.actions.length > 0')
|
||||
v-divider.mt-3
|
||||
@ -216,7 +216,9 @@ export default {
|
||||
runningAction: false,
|
||||
runningActionHandler: '',
|
||||
selectedTarget: '',
|
||||
target: {},
|
||||
target: {
|
||||
supportedModes: []
|
||||
},
|
||||
targets: [],
|
||||
status: []
|
||||
}
|
||||
@ -265,6 +267,7 @@ export default {
|
||||
this.$store.commit(`loadingStop`, 'admin-storage-savetargets')
|
||||
},
|
||||
getDefaultSchedule(val) {
|
||||
if (!val) { return 'N/A' }
|
||||
return moment.duration(val).format('y [years], M [months], d [days], h [hours], m [minutes]')
|
||||
},
|
||||
async executeAction(targetKey, handler) {
|
||||
|
@ -0,0 +1,12 @@
|
||||
mutation($providers: [AnalyticsProviderInput]!) {
|
||||
analytics {
|
||||
updateProviders(providers: $providers) {
|
||||
responseResult {
|
||||
succeeded
|
||||
errorCode
|
||||
slug
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
client/graph/admin/analytics/analytics-query-providers.gql
Normal file
17
client/graph/admin/analytics/analytics-query-providers.gql
Normal file
@ -0,0 +1,17 @@
|
||||
query {
|
||||
analytics {
|
||||
providers {
|
||||
isEnabled
|
||||
key
|
||||
title
|
||||
description
|
||||
isAvailable
|
||||
logo
|
||||
website
|
||||
config {
|
||||
key
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
client/static/svg/icon-line-chart.svg
Normal file
29
client/static/svg/icon-line-chart.svg
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 20.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Слой_1" x="0px" y="0px" viewBox="0 0 64 64" style="enable-background:new 0 0 64 64;" xml:space="preserve" width="96px" height="96px">
|
||||
<linearGradient id="SVGID_1__43631" gradientUnits="userSpaceOnUse" x1="31.7157" y1="11.1698" x2="32.2157" y2="53.0448" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#1A6DFF"/>
|
||||
<stop offset="1" style="stop-color:#C822FF"/>
|
||||
</linearGradient>
|
||||
<path style="fill:url(#SVGID_1__43631);" d="M56,39h-2v11H43V39.899c2.279-0.465,4-2.484,4-4.899c0-1.328-0.529-2.53-1.378-3.427 l6.606-8.257c0.547,0.286,1.143,0.487,1.772,0.594V35h2V23.91c2.833-0.478,5-2.942,5-5.91c0-3.309-2.691-6-6-6s-6,2.691-6,6 c0,1.588,0.625,3.03,1.635,4.104l-6.649,8.312C43.376,30.151,42.706,30,42,30c-1.017,0-1.962,0.309-2.753,0.833l-9.362-9.362 C30.584,20.49,31,19.294,31,18c0-3.309-2.691-6-6-6s-6,2.691-6,6c0,1.294,0.416,2.49,1.115,3.471l-9.362,9.362 C9.962,30.309,9.017,30,8,30c-2.757,0-5,2.243-5,5c0,2.414,1.721,4.434,4,4.899V50H3v2h58v-2h-5V39z M55,14c2.206,0,4,1.794,4,4 s-1.794,4-4,4s-4-1.794-4-4S52.794,14,55,14z M42,32c1.654,0,3,1.346,3,3s-1.346,3-3,3s-3-1.346-3-3S40.346,32,42,32z M25,14 c2.206,0,4,1.794,4,4s-1.794,4-4,4s-4-1.794-4-4S22.794,14,25,14z M5,35c0-1.654,1.346-3,3-3s3,1.346,3,3s-1.346,3-3,3 S5,36.654,5,35z M9,39.899c2.279-0.465,4-2.484,4-4.899c0-1.017-0.309-1.962-0.833-2.753l9.362-9.362 C22.251,23.4,23.091,23.756,24,23.91V35h2V23.91c0.909-0.154,1.749-0.51,2.471-1.025l9.362,9.362C37.309,33.038,37,33.983,37,35 c0,2.414,1.721,4.434,4,4.899V50H26V39h-2v11H9V39.899z"/>
|
||||
<linearGradient id="SVGID_2__43631" gradientUnits="userSpaceOnUse" x1="25" y1="15.6667" x2="25" y2="20.6916" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#6DC7FF"/>
|
||||
<stop offset="1" style="stop-color:#E6ABFF"/>
|
||||
</linearGradient>
|
||||
<circle style="fill:url(#SVGID_2__43631);" cx="25" cy="18" r="2"/>
|
||||
<linearGradient id="SVGID_3__43631" gradientUnits="userSpaceOnUse" x1="55" y1="15.6667" x2="55" y2="20.6916" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#6DC7FF"/>
|
||||
<stop offset="1" style="stop-color:#E6ABFF"/>
|
||||
</linearGradient>
|
||||
<circle style="fill:url(#SVGID_3__43631);" cx="55" cy="18" r="2"/>
|
||||
<linearGradient id="SVGID_4__43631" gradientUnits="userSpaceOnUse" x1="42" y1="31.8333" x2="42" y2="38.3419" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#6DC7FF"/>
|
||||
<stop offset="1" style="stop-color:#E6ABFF"/>
|
||||
</linearGradient>
|
||||
<circle style="fill:url(#SVGID_4__43631);" cx="42" cy="35" r="3"/>
|
||||
<linearGradient id="SVGID_5__43631" gradientUnits="userSpaceOnUse" x1="8" y1="31.8333" x2="8" y2="38.3419" spreadMethod="reflect">
|
||||
<stop offset="0" style="stop-color:#6DC7FF"/>
|
||||
<stop offset="1" style="stop-color:#E6ABFF"/>
|
||||
</linearGradient>
|
||||
<circle style="fill:url(#SVGID_5__43631);" cx="8" cy="35" r="3"/>
|
||||
</svg>
|
After Width: | Height: | Size: 3.0 KiB |
@ -226,7 +226,7 @@
|
||||
"graphql-voyager": "1.0.0-rc.27",
|
||||
"hammerjs": "2.0.8",
|
||||
"html-webpack-plugin": "3.2.0",
|
||||
"html-webpack-pug-plugin": "0.3.0",
|
||||
"html-webpack-pug-plugin": "2.0.0",
|
||||
"i18next-xhr-backend": "3.0.0",
|
||||
"ignore-loader": "0.1.2",
|
||||
"js-cookie": "2.2.0",
|
||||
|
@ -63,6 +63,7 @@ module.exports = {
|
||||
* Post-Master Boot Sequence
|
||||
*/
|
||||
async postBootMaster() {
|
||||
await WIKI.models.analytics.refreshProvidersFromDisk()
|
||||
await WIKI.models.authentication.refreshStrategiesFromDisk()
|
||||
await WIKI.models.editors.refreshEditorsFromDisk()
|
||||
await WIKI.models.loggers.refreshLoggersFromDisk()
|
||||
|
13
server/db/migrations-sqlite/2.0.0-beta.205.js
Normal file
13
server/db/migrations-sqlite/2.0.0-beta.205.js
Normal file
@ -0,0 +1,13 @@
|
||||
exports.up = knex => {
|
||||
return knex.schema
|
||||
.createTable('analytics', table => {
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config').notNullable()
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => {
|
||||
return knex.schema
|
||||
.dropTableIfExists('analytics')
|
||||
}
|
17
server/db/migrations/2.0.0-beta.205.js
Normal file
17
server/db/migrations/2.0.0-beta.205.js
Normal file
@ -0,0 +1,17 @@
|
||||
exports.up = knex => {
|
||||
const dbCompat = {
|
||||
charset: (WIKI.config.db.type === `mysql` || WIKI.config.db.type === `mariadb`)
|
||||
}
|
||||
return knex.schema
|
||||
.createTable('analytics', table => {
|
||||
if (dbCompat.charset) { table.charset('utf8mb4') }
|
||||
table.string('key').notNullable().primary()
|
||||
table.boolean('isEnabled').notNullable().defaultTo(false)
|
||||
table.json('config').notNullable()
|
||||
})
|
||||
}
|
||||
|
||||
exports.down = knex => {
|
||||
return knex.schema
|
||||
.dropTableIfExists('analytics')
|
||||
}
|
56
server/graph/resolvers/analytics.js
Normal file
56
server/graph/resolvers/analytics.js
Normal file
@ -0,0 +1,56 @@
|
||||
const _ = require('lodash')
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async analytics() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async analytics() { return {} }
|
||||
},
|
||||
AnalyticsQuery: {
|
||||
async providers(obj, args, context, info) {
|
||||
let providers = await WIKI.models.analytics.getProviders(args.isEnabled)
|
||||
providers = providers.map(stg => {
|
||||
const providerInfo = _.find(WIKI.data.analytics, ['key', stg.key]) || {}
|
||||
return {
|
||||
...providerInfo,
|
||||
...stg,
|
||||
config: _.sortBy(_.transform(stg.config, (res, value, key) => {
|
||||
const configData = _.get(providerInfo.props, key, {})
|
||||
res.push({
|
||||
key,
|
||||
value: JSON.stringify({
|
||||
...configData,
|
||||
value
|
||||
})
|
||||
})
|
||||
}, []), 'key')
|
||||
}
|
||||
})
|
||||
return providers
|
||||
}
|
||||
},
|
||||
AnalyticsMutation: {
|
||||
async updateProviders(obj, args, context) {
|
||||
try {
|
||||
for (let str of args.providers) {
|
||||
await WIKI.models.analytics.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', str.key)
|
||||
}
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Providers updated successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
server/graph/schemas/analytics.graphql
Normal file
53
server/graph/schemas/analytics.graphql
Normal file
@ -0,0 +1,53 @@
|
||||
# ===============================================
|
||||
# ANALYTICS
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
analytics: AnalyticsQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
analytics: AnalyticsMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsQuery {
|
||||
providers(
|
||||
isEnabled: Boolean
|
||||
): [AnalyticsProvider]
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsMutation {
|
||||
updateProviders(
|
||||
providers: [AnalyticsProviderInput]!
|
||||
): DefaultResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsProvider {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
props: [String]
|
||||
title: String!
|
||||
description: String
|
||||
isAvailable: Boolean
|
||||
logo: String
|
||||
website: String
|
||||
icon: String
|
||||
config: [KeyValuePair] @auth(requires: ["manage:system"])
|
||||
}
|
||||
input AnalyticsProviderInput {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
config: [KeyValuePairInput]
|
||||
}
|
96
server/models/analytics.js
Normal file
96
server/models/analytics.js
Normal file
@ -0,0 +1,96 @@
|
||||
const Model = require('objection').Model
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const yaml = require('js-yaml')
|
||||
const commonHelper = require('../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Analytics model
|
||||
*/
|
||||
module.exports = class Analytics extends Model {
|
||||
static get tableName() { return 'analytics' }
|
||||
static get idColumn() { return 'key' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['key', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
key: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static get jsonAttributes() {
|
||||
return ['config']
|
||||
}
|
||||
|
||||
static async getProviders(isEnabled) {
|
||||
const providers = await WIKI.models.analytics.query().where(_.isBoolean(isEnabled) ? { isEnabled } : {})
|
||||
return _.sortBy(providers, ['key'])
|
||||
}
|
||||
|
||||
static async refreshProvidersFromDisk() {
|
||||
let trx
|
||||
try {
|
||||
const dbProviders = await WIKI.models.analytics.query()
|
||||
|
||||
// -> Fetch definitions from disk
|
||||
const analyticsDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/analytics'))
|
||||
let diskProviders = []
|
||||
for (let dir of analyticsDirs) {
|
||||
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/analytics', dir, 'definition.yml'), 'utf8')
|
||||
diskProviders.push(yaml.safeLoad(def))
|
||||
}
|
||||
WIKI.data.analytics = diskProviders.map(provider => ({
|
||||
...provider,
|
||||
props: commonHelper.parseModuleProps(provider.props)
|
||||
}))
|
||||
|
||||
let newProviders = []
|
||||
for (let provider of WIKI.data.analytics) {
|
||||
if (!_.some(dbProviders, ['key', provider.key])) {
|
||||
newProviders.push({
|
||||
key: provider.key,
|
||||
isEnabled: false,
|
||||
config: _.transform(provider.props, (result, value, key) => {
|
||||
_.set(result, key, value.default)
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
} else {
|
||||
const providerConfig = _.get(_.find(dbProviders, ['key', provider.key]), 'config', {})
|
||||
await WIKI.models.analytics.query().patch({
|
||||
config: _.transform(provider.props, (result, value, key) => {
|
||||
if (!_.has(result, key)) {
|
||||
_.set(result, key, value.default)
|
||||
}
|
||||
return result
|
||||
}, providerConfig)
|
||||
}).where('key', provider.key)
|
||||
}
|
||||
}
|
||||
if (newProviders.length > 0) {
|
||||
trx = await WIKI.models.Objection.transaction.start(WIKI.models.knex)
|
||||
for (let provider of newProviders) {
|
||||
await WIKI.models.analytics.query(trx).insert(provider)
|
||||
}
|
||||
await trx.commit()
|
||||
WIKI.logger.info(`Loaded ${newProviders.length} new analytics providers: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new analytics providers found: [ SKIPPED ]`)
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new analytics providers: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
if (trx) {
|
||||
trx.rollback()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
server/modules/analytics/azureinsights/definition.yml
Normal file
23
server/modules/analytics/azureinsights/definition.yml
Normal file
@ -0,0 +1,23 @@
|
||||
key: azureinsights
|
||||
title: Azure Application Insights
|
||||
description: Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/azure.svg
|
||||
website: https://azure.microsoft.com/en-us/services/monitor/
|
||||
isAvailable: true
|
||||
props:
|
||||
instrumentationKey:
|
||||
type: String
|
||||
title: Instrumentation Key
|
||||
hint: Found in the Azure Portal in your Application Insights resource panel
|
||||
order: 1
|
||||
codeHead: |
|
||||
<script type="text/javascript">
|
||||
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){
|
||||
function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n)})}}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/next/ai.2.min.js",i.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{t.cookie=i.cookie}catch(e){}t.queue=[],t.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var s="Track"+r[0];if(n("start"+s),n("stop"+s),n("setAuthenticatedUserContext"),n("clearAuthenticatedUserContext"),n("flush"),!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var o=a[r];a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return!0!==c&&t["_"+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s}),c},e.autoExceptionInstrumented=!0}return t
|
||||
}({
|
||||
instrumentationKey:"{{instrumentationKey}}"
|
||||
});
|
||||
|
||||
window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({});
|
||||
</script>
|
45
server/modules/analytics/countly/definition.yml
Normal file
45
server/modules/analytics/countly/definition.yml
Normal file
@ -0,0 +1,45 @@
|
||||
key: countly
|
||||
title: Countly
|
||||
description: Countly is the best analytics platform to understand and enhance customer journeys in web, desktop and mobile applications.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/countly.svg
|
||||
website: https://count.ly/
|
||||
isAvailable: true
|
||||
props:
|
||||
appKey:
|
||||
type: String
|
||||
title: App Key
|
||||
hint: The App Key found under Management > Applications
|
||||
order: 1
|
||||
serverUrl:
|
||||
type: String
|
||||
title: Server URL
|
||||
hint: The Count.ly server to report to. e.g. https://us-example.count.ly
|
||||
order: 2
|
||||
codeHead: |
|
||||
<script type='text/javascript'>
|
||||
//some default pre init
|
||||
var Countly = Countly || {};
|
||||
Countly.q = Countly.q || [];
|
||||
|
||||
//provide countly initialization parameters
|
||||
Countly.app_key = '{{appKey}}';
|
||||
Countly.url = '{{serverUrl}}';
|
||||
|
||||
Countly.q.push(['track_sessions']);
|
||||
Countly.q.push(['track_pageview']);
|
||||
Countly.q.push(['track_clicks']);
|
||||
Countly.q.push(['track_scrolls']);
|
||||
Countly.q.push(['track_errors']);
|
||||
Countly.q.push(['track_links']);
|
||||
|
||||
//load countly script asynchronously
|
||||
(function() {
|
||||
var cly = document.createElement('script'); cly.type = 'text/javascript';
|
||||
cly.async = true;
|
||||
//enter url of script here
|
||||
cly.src = 'https://cdnjs.cloudflare.com/ajax/libs/countly-sdk-web/18.8.2/countly.min.js';
|
||||
cly.onload = function(){Countly.init()};
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
|
||||
})();
|
||||
</script>
|
36
server/modules/analytics/elasticapm/definition.yml
Normal file
36
server/modules/analytics/elasticapm/definition.yml
Normal file
@ -0,0 +1,36 @@
|
||||
key: elasticapm
|
||||
title: Elasticsearch APM RUM
|
||||
description: Real User Monitoring captures user interaction with clients such as web browsers.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/elasticsearch-apm.svg
|
||||
website: https://www.elastic.co/solutions/apm
|
||||
isAvailable: true
|
||||
props:
|
||||
serverUrl:
|
||||
type: String
|
||||
title: APM Server URL
|
||||
hint: The full URL to your APM server, including the port
|
||||
default: http://apm.example.com:8200
|
||||
order: 1
|
||||
serviceName:
|
||||
type: String
|
||||
title: Service Name
|
||||
hint: The name of the client reported to APM
|
||||
default: wiki-js
|
||||
order: 2
|
||||
environment:
|
||||
type: String
|
||||
title: Environment
|
||||
hint: e.g. production/development/test
|
||||
default: ''
|
||||
order: 3
|
||||
codeHead: |
|
||||
<!-- Elastic APM RUM -->
|
||||
<script async src="https://unpkg.com/@elastic/apm-rum/dist/bundles/elastic-apm-rum.umd.min.js"></script>
|
||||
<script>
|
||||
elasticApm.init({
|
||||
serviceName: '{{serviceName}}',
|
||||
serverUrl: '{{serverUrl}}',
|
||||
environment: '{{environment}}'
|
||||
})
|
||||
</script>
|
34
server/modules/analytics/fathom/definition.yml
Normal file
34
server/modules/analytics/fathom/definition.yml
Normal file
@ -0,0 +1,34 @@
|
||||
key: fathom
|
||||
title: Fathom
|
||||
description: Fathom Analytics provides simple, useful website stats without tracking or storing personal data of your users.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/fathom.svg
|
||||
website: https://usefathom.com/
|
||||
isAvailable: true
|
||||
props:
|
||||
host:
|
||||
type: String
|
||||
title: Fathom Server Host
|
||||
hint: The hostname / ip adress where Fathom is installed, without the trailing slash. e.g. https://fathom.example.com
|
||||
order: 1
|
||||
siteId:
|
||||
type: String
|
||||
title: Site ID
|
||||
hint: The alphanumeric identifier of your site
|
||||
order: 2
|
||||
codeHead: |
|
||||
<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
|
||||
<script>
|
||||
(function(f, a, t, h, o, m){
|
||||
a[h]=a[h]||function(){
|
||||
(a[h].q=a[h].q||[]).push(arguments)
|
||||
};
|
||||
o=f.createElement('script'),
|
||||
m=f.getElementsByTagName('script')[0];
|
||||
o.async=1; o.src=t; o.id='fathom-script';
|
||||
m.parentNode.insertBefore(o,m)
|
||||
})(document, window, '{{host}}/tracker.js', 'fathom');
|
||||
fathom('set', 'siteId', '{{siteId}}');
|
||||
fathom('trackPageview');
|
||||
</script>
|
||||
<!-- / Fathom -->
|
31
server/modules/analytics/fullstory/definition.yml
Normal file
31
server/modules/analytics/fullstory/definition.yml
Normal file
@ -0,0 +1,31 @@
|
||||
key: fullstory
|
||||
title: FullStory
|
||||
description: FullStory is your digital experience analytics platform for on-the-fly funnels, pixel-perfect replay, custom events, heat maps, advanced search, Dev Tools, and more.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/fullstory.svg
|
||||
website: https://www.fullstory.com
|
||||
isAvailable: true
|
||||
props:
|
||||
org:
|
||||
type: String
|
||||
title: Organization ID
|
||||
hint: A 5 alphanumeric identifier, e.g. XXXXX
|
||||
order: 1
|
||||
codeHead: |
|
||||
<script>
|
||||
window['_fs_debug'] = false;
|
||||
window['_fs_host'] = 'fullstory.com';
|
||||
window['_fs_org'] = '{{org}}';
|
||||
window['_fs_namespace'] = 'FS';
|
||||
(function(m,n,e,t,l,o,g,y){
|
||||
if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}
|
||||
g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];
|
||||
o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src='https://'+_fs_host+'/s/fs.js';
|
||||
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
|
||||
g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};
|
||||
g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};
|
||||
g.consent=function(a){g("consent",!arguments.length||a)};
|
||||
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
|
||||
g.clearUserCookie=function(){};
|
||||
})(window,document,window['_fs_namespace'],'script','user');
|
||||
</script>
|
23
server/modules/analytics/google/definition.yml
Normal file
23
server/modules/analytics/google/definition.yml
Normal file
@ -0,0 +1,23 @@
|
||||
key: google
|
||||
title: Google Analytics
|
||||
description: Google specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/google-analytics.svg
|
||||
website: https://analytics.google.com/
|
||||
isAvailable: true
|
||||
props:
|
||||
propertyTrackingId:
|
||||
type: String
|
||||
title: Property Tracking ID
|
||||
hint: UA-XXXXXXX-X
|
||||
order: 1
|
||||
codeHead: |
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{propertyTrackingId}}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{{propertyTrackingId}}');
|
||||
</script>
|
26
server/modules/analytics/gtm/definition.yml
Normal file
26
server/modules/analytics/gtm/definition.yml
Normal file
@ -0,0 +1,26 @@
|
||||
key: gtm
|
||||
title: Google Tag Manager
|
||||
description: Google specializes in Internet-related services and products, which include online advertising technologies, search engine, cloud computing, software, and hardware.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/google-tag-manager.svg
|
||||
website: https://tagmanager.google.com
|
||||
isAvailable: true
|
||||
props:
|
||||
containerTrackingId:
|
||||
type: String
|
||||
title: Container Tracking ID
|
||||
hint: GTM-XXXXXXX
|
||||
order: 1
|
||||
codeHead: |
|
||||
<!-- Google Tag Manager -->
|
||||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','{{containerTrackingId}}');</script>
|
||||
<!-- End Google Tag Manager -->
|
||||
codeBodyStart: |
|
||||
<!-- Google Tag Manager (noscript) -->
|
||||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{containerTrackingId}}"
|
||||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||
<!-- End Google Tag Manager (noscript) -->
|
25
server/modules/analytics/hotjar/definition.yml
Normal file
25
server/modules/analytics/hotjar/definition.yml
Normal file
@ -0,0 +1,25 @@
|
||||
key: hotjar
|
||||
title: Hotjar
|
||||
description: Hotjar is the fast & visual way to understand your users, providing everything your team needs to uncover insights and make the right changes to your site.
|
||||
author: requarks.io
|
||||
logo: https://static.requarks.io/logo/hotjar.svg
|
||||
website: https://www.hotjar.com
|
||||
isAvailable: true
|
||||
props:
|
||||
siteId:
|
||||
type: String
|
||||
title: Site ID
|
||||
hint: A numeric identifier of your site
|
||||
order: 1
|
||||
codeHead: |
|
||||
<!-- Hotjar Tracking Code -->
|
||||
<script>
|
||||
(function(h,o,t,j,a,r){
|
||||
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
||||
h._hjSettings={hjid:{{siteId}},hjsv:6};
|
||||
a=o.getElementsByTagName('head')[0];
|
||||
r=o.createElement('script');r.async=1;
|
||||
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
||||
a.appendChild(r);
|
||||
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
||||
</script>
|
@ -7,9 +7,9 @@ html
|
||||
meta(name='theme-color', content='#333333')
|
||||
meta(name='msapplication-TileColor', content='#333333')
|
||||
meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png')
|
||||
|
||||
|
||||
title= pageMeta.title + ' | ' + config.title
|
||||
|
||||
|
||||
//- SEO / OpenGraph
|
||||
meta(name='description', content=pageMeta.description)
|
||||
meta(property='og:title', content=pageMeta.title)
|
||||
@ -18,7 +18,7 @@ html
|
||||
meta(property='og:image', content=pageMeta.image)
|
||||
meta(property='og:url', content=pageMeta.url)
|
||||
meta(property='og:site_name', content=config.title)
|
||||
|
||||
|
||||
//- Favicon
|
||||
each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180]
|
||||
link(rel='apple-touch-icon', sizes=favsize + 'x' + favsize, href='/favicons/apple-icon-' + favsize + 'x' + favsize + '.png')
|
||||
@ -26,32 +26,32 @@ html
|
||||
each favsize in [32, 96, 16]
|
||||
link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
|
||||
link(rel='manifest', href='/manifest.json')
|
||||
|
||||
|
||||
//- Site Properties
|
||||
script.
|
||||
var siteConfig = !{JSON.stringify(siteConfig)}; var siteLangs = !{JSON.stringify(langs)}
|
||||
|
||||
|
||||
//- CSS
|
||||
|
||||
|
||||
|
||||
//- JS
|
||||
|
||||
|
||||
|
||||
|
||||
script(
|
||||
type='text/javascript'
|
||||
src='/js/runtime.js'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
script(
|
||||
type='text/javascript'
|
||||
src='/js/app.js'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
block head
|
||||
|
||||
|
||||
body
|
||||
block body
|
||||
|
@ -8,7 +8,7 @@ html
|
||||
meta(name='msapplication-TileColor', content='#333333')
|
||||
meta(name='msapplication-TileImage', content='/favicons/ms-icon-144x144.png')
|
||||
title Wiki.js Setup
|
||||
|
||||
|
||||
//- Favicon
|
||||
each favsize in [57, 60, 72, 76, 114, 120, 144, 152, 180]
|
||||
link(rel='apple-touch-icon', sizes=favsize + 'x' + favsize, href='/favicons/apple-icon-' + favsize + 'x' + favsize + '.png')
|
||||
@ -16,31 +16,31 @@ html
|
||||
each favsize in [32, 96, 16]
|
||||
link(rel='icon', type='image/png', sizes=favsize + 'x' + favsize, href='/favicons/favicon-' + favsize + 'x' + favsize + '.png')
|
||||
link(rel='manifest', href='/manifest.json')
|
||||
|
||||
|
||||
//- Site Lang
|
||||
script.
|
||||
var siteConfig = !{JSON.stringify({ title: config.title })}
|
||||
|
||||
|
||||
//- CSS
|
||||
|
||||
|
||||
|
||||
//- JS
|
||||
|
||||
|
||||
|
||||
|
||||
script(
|
||||
type='text/javascript'
|
||||
src='/js/runtime.js'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
script(
|
||||
type='text/javascript'
|
||||
src='/js/setup.js'
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
body
|
||||
#root
|
||||
setup(telemetry-id=telemetryClientID, wiki-version=packageObj.version)
|
||||
|
Loading…
Reference in New Issue
Block a user