@socialgouv/matomo-postgres
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "@socialgouv/matomo-postgres", | ||
"description": "Extract visitor events from Matomo API and push to Postgres", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"types": "types/index.d.ts", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
# @socialgouv/matomo-postgres | ||
Extract matomo data and push to Postgres | ||
![header](./header.png) | ||
Use Matomo [`Live.getLastVisitsDetails`](https://developer.matomo.org/api-reference/reporting-api) API to extract visits informations. | ||
Extract matomo data from [`Live.getLastVisitsDetails`](https://developer.matomo.org/api-reference/reporting-api) API and push events and visits informations to Postgres. | ||
@@ -7,0 +7,0 @@ ## Usage |
@@ -15,3 +15,3 @@ const mock_pgQuery = jest.fn(); | ||
const NB_REQUEST_TO_INIT_DB = 5; // Number of query to init DB (createTable.js) | ||
const NB_REQUEST_TO_INIT_DB = 6; // Number of query to init DB (createTable.js) | ||
const TEST_DATE = new Date(); | ||
@@ -18,0 +18,0 @@ |
const { Client } = require("pg"); | ||
const { DESTINATION_TABLE } = require("./config"); | ||
/** | ||
@@ -9,3 +10,4 @@ * | ||
async function createTable(client) { | ||
const text = `CREATE TABLE IF NOT EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)} | ||
const table = client.escapeIdentifier(DESTINATION_TABLE); | ||
const text = `CREATE TABLE IF NOT EXISTS ${table} | ||
( | ||
@@ -32,3 +34,3 @@ idsite text, | ||
action_eventname text, | ||
action_eventvalue text, | ||
action_eventvalue decimal, | ||
action_timespent text, | ||
@@ -42,19 +44,13 @@ action_timestamp timestamp with time zone, | ||
)`; | ||
await client.query(text, []); | ||
const addUserCustomDimensionColumn = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)} | ||
ADD COLUMN IF NOT EXISTS "usercustomdimensions" json;`; | ||
await client.query(addUserCustomDimensionColumn, []); | ||
const addActionUrlColumn = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)} | ||
ADD COLUMN IF NOT EXISTS "action_url" text;`; | ||
await client.query(addActionUrlColumn, []); | ||
const migrations = [ | ||
`ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "usercustomdimensions" json;`, | ||
`ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "action_url" text;`, | ||
`ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "sitesearchkeyword" text;`, | ||
`ALTER TABLE IF EXISTS ${table} ADD COLUMN IF NOT EXISTS "action_title" text;`, | ||
`ALTER TABLE IF EXISTS ${table} ALTER COLUMN action_eventvalue TYPE decimal USING action_eventvalue::decimal;`, | ||
]; | ||
const addSiteSearchKeyword = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)} | ||
ADD COLUMN IF NOT EXISTS "sitesearchkeyword" text;`; | ||
await client.query(addSiteSearchKeyword, []); | ||
const addActionName = `ALTER TABLE IF EXISTS ${client.escapeIdentifier(DESTINATION_TABLE)} | ||
ADD COLUMN IF NOT EXISTS "action_title" text;`; | ||
await client.query(addActionName, []); | ||
// --------------------------------------------- // | ||
@@ -64,4 +60,9 @@ // If you add new query: Don't forget to update // | ||
// --------------------------------------------- // | ||
for(const query of migrations) { | ||
await client.query(query, []); | ||
} | ||
} | ||
module.exports = { createTable }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152065
23
969