Skip to content

Commit

Permalink
♻️ refactor: use generic-connector-client for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
david-vaclavek committed Apr 16, 2024
1 parent 45acefe commit 2570424
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 82 deletions.
61 changes: 38 additions & 23 deletions admin/src/modules/@common/services/product-analytics-service.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import AnalyticsService from "../../../plugins/analytics-service";
import GenericConnectorClient from "../../../plugins/generic-connector-client";

export default class ProductAnalyticsService {
static async trackAppConnected(userId, project, params = {}) {
try {
const data = this.buildData(userId, "Strapi Connected", project, params);
await AnalyticsService.trackEvent(data.event, {
...data.data,
userId,
category: "Project",
const data = this.buildData("Strapi Connected", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
...data.data,
userId,
orgId: project.orgId,
category: "Project",
}
});
} catch (e) {
console.warn(e);
Expand All @@ -16,11 +20,15 @@ export default class ProductAnalyticsService {

static async trackAppDisconnected(userId, project, params = {}) {
try {
const data = this.buildData(userId, "Strapi Disconnected", project, params);
await AnalyticsService.trackEvent(data.event, {
...data.data,
userId,
category: "Project",
const data = this.buildData("Strapi Disconnected", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
...data.data,
userId,
orgId: project.orgId,
category: "Project",
}
});
} catch (e) {
console.warn(e);
Expand All @@ -29,11 +37,15 @@ export default class ProductAnalyticsService {

static async trackUploadToLocalazy(userId, project, params = {}) {
try {
const data = this.buildData(userId, "Strapi Upload", project, params);
await AnalyticsService.trackEvent(data.event, {
...data.data,
userId,
category: "Project",
const data = this.buildData("Strapi Upload", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
...data.data,
userId,
orgId: project.orgId,
category: "Project",
}
});
} catch (e) {
console.warn(e);
Expand All @@ -42,22 +54,25 @@ export default class ProductAnalyticsService {

static async trackDownloadToStrapi(userId, project, params = {}) {
try {
const data = this.buildData(userId, "Strapi Download", project, params);
await AnalyticsService.trackEvent(data.event, {
...data.data,
userId,
category: "Project",
const data = this.buildData("Strapi Download", project, params);
await GenericConnectorClient.analytics.track({
event: data.event,
data: {
...data.data,
userId,
orgId: project.orgId,
category: "Project",
}
});
} catch (e) {
console.warn(e);
}
}

static buildData(userId, event, project, params) {
static buildData(event, project, params) {
return {
event,
data: {
"User Id": userId,
"Project Id": project.id,
"Project Name": project.name,
...params,
Expand Down
14 changes: 0 additions & 14 deletions admin/src/plugins/analytics-service.js

This file was deleted.

9 changes: 9 additions & 0 deletions admin/src/plugins/generic-connector-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { GenericConnectorClient, Services } from "@localazy/generic-connector-client";
import config from "../config";

const client = new GenericConnectorClient({
pluginId: Services.STRAPI,
genericConnectorUrl: config.LOCALAZY_PLUGIN_CONNECTOR_API_URL,
});

export default client;
45 changes: 0 additions & 45 deletions admin/src/utils/createPluginConnectorAxiosInstance.js

This file was deleted.

0 comments on commit 2570424

Please sign in to comment.