Skip to content

Commit

Permalink
✨ feat(Analytics): send plugin version in request
Browse files Browse the repository at this point in the history
  • Loading branch information
david-vaclavek committed May 9, 2024
1 parent dbfd6d8 commit 26d3aeb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
16 changes: 16 additions & 0 deletions admin/src/modules/@common/services/plugin.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable no-useless-catch */
import createAxiosInstance from "../../../utils/createAxiosInstance";

const axiosInstance = createAxiosInstance();

export default class PluginService {
static async getPluginVersion() {
try {
const result = await axiosInstance.get("/strapi/version");

return result.data;
} catch (e) {
throw e;
}
}
}
14 changes: 9 additions & 5 deletions admin/src/modules/@common/services/product-analytics-service.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import GenericConnectorClient from "../../../plugins/generic-connector-client";
import PluginService from "./plugin.service";

export default class ProductAnalyticsService {
static async trackAppConnected(userId, project, params = {}) {
try {
const data = this.buildData("Strapi Connected", project, params);
const data = await this.buildData("Strapi Connected", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
Expand All @@ -20,7 +21,7 @@ export default class ProductAnalyticsService {

static async trackAppDisconnected(userId, project, params = {}) {
try {
const data = this.buildData("Strapi Disconnected", project, params);
const data = await this.buildData("Strapi Disconnected", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
Expand All @@ -37,7 +38,7 @@ export default class ProductAnalyticsService {

static async trackUploadToLocalazy(userId, project, params = {}) {
try {
const data = this.buildData("Strapi Upload", project, params);
const data = await this.buildData("Strapi Upload", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
Expand All @@ -54,7 +55,7 @@ export default class ProductAnalyticsService {

static async trackDownloadToStrapi(userId, project, params = {}) {
try {
const data = this.buildData("Strapi Download", project, params);
const data = await this.buildData("Strapi Download", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
Expand All @@ -69,12 +70,15 @@ export default class ProductAnalyticsService {
}
}

static buildData(event, project, params) {
static async buildData(event, project, params) {
const { version } = await PluginService.getPluginVersion();

return {
event,
data: {
"Project Id": project.id,
"Project Name": project.name,
version,
...params,
},
};
Expand Down
8 changes: 8 additions & 0 deletions server/controllers/strapi-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ module.exports = {
async postLifecycleLocalazyWebhooks(ctx) {
strapi.log("done");
},
async getPluginVersion(ctx) {
ctx.body = {
version: await strapi
.plugin("localazy")
.service("strapiService")
.getPluginVersion()
}
}
};
8 changes: 8 additions & 0 deletions server/routes/strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ module.exports = [
policies: [],
},
},
{
method: "GET",
path: `${ROUTE_PREFIX}/version`,
handler: "strapiController.getPluginVersion",
config: {
policies: [],
},
},
];
3 changes: 3 additions & 0 deletions server/services/strapi-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ module.exports = ({ strapi }) => ({
const models = strapi.db.config.models;
return buildPopulate(models, modelUid);
},
async getPluginVersion() {
return require("../../package.json").version;
}
});

0 comments on commit 26d3aeb

Please sign in to comment.