* Fix spacing issues on mobile * Added back linting on modules directory. Please don't look at the dirty fixes :x * Add support for responsive ads. * Add lazy loading of images.
36 lines
1000 B
JavaScript
36 lines
1000 B
JavaScript
// eslint-disable-next-line require-await
|
|
export default async function (ctx, inject) {
|
|
const config = (ctx.$config && ctx.$config.analytics) || {}
|
|
|
|
const url = config.script_url ?? '<%= options.script_url %>'
|
|
const tag = config.tracking_code ?? '<%= options.tracking_code %>'
|
|
// eslint-disable-next-line
|
|
const enabled = config.enabled ?? ('<%= options.enabled || false %>' === 'true');
|
|
// Check if the parameters are not changed by runtime config:
|
|
|
|
const UNAMI_LIB_TAG_ID = '<%= options.UNAMI_LIB_TAG_ID %>'
|
|
|
|
if (!enabled) {
|
|
return
|
|
}
|
|
|
|
const injectScript = (script) => {
|
|
const scriptIndex = ctx.app.head.script.findIndex(
|
|
(s) => s.hid === script.hid
|
|
)
|
|
if (scriptIndex !== -1) {
|
|
ctx.app.head.script[scriptIndex] = script
|
|
} else {
|
|
ctx.app.head.script.push(script)
|
|
}
|
|
}
|
|
const analyticsScript = {
|
|
hid: UNAMI_LIB_TAG_ID,
|
|
src: url,
|
|
'data-website-id': tag,
|
|
async: true,
|
|
defer: true,
|
|
}
|
|
injectScript(analyticsScript)
|
|
}
|