Skip to content

Commit

Permalink
LOC-1096 - Fix Analytics User Identification Within Integrations (#51)
Browse files Browse the repository at this point in the history
* 🚧 refactor: use `api-client` and `generic-connector-client`

* ♻️ refactor: use `generic-connector-client` for analytics

* ♻️ refactor: upload process

* ♻️ refactor: download proces (`api-client`)

* 🐛 fix: (`deprecate-event-entry-in-localazy-hook`) `client-api` result

* ⚰️ code: remove dead code

* 🐛 fix: (`supported-custom-field-plugins`) add reference to server side

* ⬆️ deps(upgrade): `api-client` and `generic-connector-client`

* ✨ feat(Analytics): send plugin version in request

---------

Co-authored-by: david-vaclavek <vaclavek.dvd@gmail.com>
  • Loading branch information
david-vaclavek and david-vaclavek committed May 9, 2024
1 parent 770ea8a commit 6000259
Show file tree
Hide file tree
Showing 28 changed files with 268 additions and 373 deletions.
2 changes: 0 additions & 2 deletions admin/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ if (process.env.STRAPI_ADMIN_LOCALAZY_ENV === "development") {
config = development;
}

console.log(config);

export default {
...config,
};
2 changes: 1 addition & 1 deletion admin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {

return component;
} catch (e) {
console.log(e);
console.error(e);
}

return null;
Expand Down
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;
}
}
}
65 changes: 42 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,18 @@
import AnalyticsService from "../../../plugins/analytics-service";
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(userId, "Strapi Connected", project, params);
await AnalyticsService.trackEvent(data.event, {
...data.data,
userId,
category: "Project",
const data = await 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 +21,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 = await 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 +38,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 = await 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,24 +55,30 @@ 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 = await 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 async buildData(event, project, params) {
const { version } = await PluginService.getPluginVersion();

return {
event,
data: {
"User Id": userId,
"Project Id": project.id,
"Project Name": project.name,
version,
...params,
},
};
Expand Down
14 changes: 7 additions & 7 deletions admin/src/modules/login/components/LoginButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useState } from "react";
import PropTypes from "prop-types";
import { Button } from "@strapi/design-system/Button";
import { useTranslation } from "react-i18next";
import { getOAuthAuthorizationUrl } from "@localazy/generic-connector-client";
import LocalazyLoginService from "../../services/localazy-login-service";
import { getStrapiDefaultLocale } from "../../../@common/utils/get-default-locale";
import { isoStrapiToLocalazy } from "../../../@common/utils/iso-locales-utils";
Expand All @@ -23,13 +24,12 @@ function LoginButton(props) {
const strapiDefaultLocale = await getStrapiDefaultLocale();
const localazyFormatLocaleCode = isoStrapiToLocalazy(strapiDefaultLocale.code);
const keys = await LocalazyLoginService.generateKeys();
const params = new URLSearchParams({
client_id: config.LOCALAZY_OAUTH_APP_CLIENT_ID,
custom_id: keys.writeKey,
allow_create: "true",
create_locale: localazyFormatLocaleCode,
});
const url = `${config.LOCALAZY_OAUTH_URL}?${params.toString()}`;
const url = getOAuthAuthorizationUrl({
clientId: config.LOCALAZY_OAUTH_APP_CLIENT_ID,
customId: keys.writeKey,
allowCreate: true,
createLocale: localazyFormatLocaleCode,
}, config.LOCALAZY_OAUTH_URL);
window.open(url);

const pollResult = await LocalazyLoginService.continuousPoll(keys.readKey);
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.

80 changes: 63 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
},
"dependencies": {
"@david-vaclavek/deep-keys": "^0.5.0",
"@localazy/ts-api": "^1.0.13",
"@localazy/api-client": "^2.1.5",
"@localazy/generic-connector-client": "^0.2.3",
"@localazy/ts-api": "^1.1.0",
"chalk": "^5.3.0",
"fs-extra": "^11.1.1",
"i18next": "^22.4.9",
Expand Down
2 changes: 0 additions & 2 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";

const myController = require("./my-controller");
const localazyUserController = require("./localazy-user-controller");
const localazyAuthController = require("./localazy-auth-controller");
const strapiController = require("./strapi-controller");
Expand All @@ -9,7 +8,6 @@ const localazyTransferController = require("./localazy-transfer-controller");
const localazyProjectController = require("./localazy-project-controller");

module.exports = {
myController,
localazyUserController,
localazyAuthController,
strapiController,
Expand Down
Loading

0 comments on commit 6000259

Please sign in to comment.