Change ads provider, and add consent system for advertising (#155)

* Add GAM integration & base for GPDR consent

* Moved consent to a specific page.

* Added functionality to the privacy page, and desactivate tracking if consent is not given.

* Added GeoEdge support, and fixed auth issues

* Fix actions issue

* Fix actions issue, attempt 2

* Added a module for analytics with consent support.

* Remove unnecessary function

* Add support for runtime config
This commit is contained in:
Redblueflame
2021-04-09 04:44:25 +02:00
committed by GitHub
parent 103ce44ba9
commit 03b2d02742
29 changed files with 1729 additions and 46 deletions

View File

@@ -0,0 +1,6 @@
export const DEFAULT_OPTIONS = {
enabled: false,
script_url: 'https://example.com',
tracking_code: 'xxx'
}
export const UNAMI_LIB_TAG_ID = 'unami-import'

View File

@@ -0,0 +1,22 @@
import {
DEFAULT_OPTIONS,
UNAMI_LIB_TAG_ID
} from './constants';
const { resolve } = require('path');
module.exports = async function module(moduleOptions) {
const options = Object.assign(DEFAULT_OPTIONS, this.options.analytics, moduleOptions);
const templatesOptions = {
...options,
UNAMI_LIB_TAG_ID
};
this.addPlugin({
src: resolve(__dirname, 'templates/plugin.js'),
fileName: 'analytics/plugin.js',
options: templatesOptions,
});
};
module.exports.meta = require('../package.json');

View File

@@ -0,0 +1,64 @@
import Vue from 'vue';
function isAnalyticsOn(ctx) {
let cookies = null
if (ctx.req != null) {
//Server side rendering
cookies = ctx.req.headers.cookie;
} else {
// Rely on the client
cookies = document.cookie;
}
let processed = {}
cookies.split(';').forEach((e) => {
let val = e.trim().split('=');
processed[val[0]] = decodeURI(val[1]);
})
let scopes = decodeURIComponent(processed['modrinth-scopes']).split(",");
return (scopes !== null && scopes.includes('analytics'));
}
export default async function (ctx, inject) {
const { app } = ctx;
const config = ctx.$config && ctx.$config.analytics || {};
const url = config.script_url ?? '<%= options.script_url %>';
const tag = config.tracking_code ?? '<%= options.tracking_code %>';
const enabled = config.enabled ?? <%= options.enabled || false %>;
// Check if the parameters are not changed by runtime config:
const UNAMI_LIB_TAG_ID = '<%= options.UNAMI_LIB_TAG_ID %>';
if (!enabled) {
console.log("Analytics are not 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);
}
};
if (isAnalyticsOn(ctx)) {
// Inject unami
const analyticsScript = {
hid: UNAMI_LIB_TAG_ID,
src: url,
'data-website-id': 'c37613de-245d-4767-90e7-ba7980a4f1a2',
async: true,
defer: true,
};
injectScript(analyticsScript);
} else {
// console.log("Analytics scope was denied.")
}
}

View File

@@ -0,0 +1,31 @@
{
"name": "@modrinth/analytics",
"version": "0.1.0",
"description": "Unami integration for Nuxtjs",
"license": "MIT",
"contributors": [
{
"name": "redblueflame <contact@redblueflame.com>"
}
],
"main": "lib/module.js",
"repository": "https://github.com/modrinth/knossos/",
"homepage": "https://github.com/modrinth/knossos/tree/master/modules/analytics",
"files": [
"lib"
],
"devDependencies": {
"codecov": "latest",
"eslint": "5.13.0",
"eslint-config-airbnb-base": "13.1.0",
"eslint-loader": "2.1.2",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jest": "22.3.0",
"eslint-plugin-vue": "5.2.1",
"jest": "24.1.0",
"jsdom": "14.0.0",
"nuxt": "2.4.3",
"request-promise-native": "1.0.5",
"standard-version": "latest"
}
}