Skip to content

Commit 9a7e01a

Browse files
Merge pull request 'feature/event-registration' (#61) from feature/event-registration into release/v3.7.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/docspace-ui-kit-react/pulls/61 Reviewed-by: Alexey Safronov <alexey.safronov@onlyoffice.com>
2 parents 5f1018b + 1f2202f commit 9a7e01a

6 files changed

Lines changed: 111 additions & 8 deletions

File tree

billing/main-tariff/sub-components/UpdatePlanButtonContainer.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { Link } from "../../../components/link";
4949
import DowngradePlanButtonContainer from "./DowngradePlanButtonContainer";
5050
import ChangePricingPlanDialog from "../../dialogs/ChangePricingPlanDialog";
5151
import { usePaymentStore } from "../../store/PaymentStoreProvider";
52+
import { AnalyticsEvents } from "../../../enums";
5253

5354
const StyledBody = styled.div`
5455
button {
@@ -184,11 +185,13 @@ const UpdatePlanButtonContainer = ({
184185
const data: { [key: string]: number } = isYearTariff
185186
? { adminyear: managersCount }
186187
: { admin: managersCount };
188+
187189
const updateRes = await paymentApi.updatePayment({
188190
quantityRequestDto: {
189191
quantity: data,
190192
},
191193
});
194+
192195
const res = updateRes?.data?.response;
193196

194197
if (res === false) {
@@ -220,6 +223,15 @@ const UpdatePlanButtonContainer = ({
220223
return;
221224
}
222225

226+
window.dataLayer = window.dataLayer || [];
227+
228+
window.dataLayer.push({
229+
event: AnalyticsEvents.Purchase,
230+
ecommerce: {
231+
items: [{ item_name: "DocSpace Business" }],
232+
},
233+
});
234+
223235
previousManagersCount = maxCountManagersByQuota;
224236
const quotaRes = await paymentApi
225237
.getQuotaPaymentInformation({

billing/services/pages/ai-tools/AiPaywallCompletePage.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { formatCurrencyValue } from "../../../utils/common";
5151

5252
import styles from "./AiPaywallCompletePage.module.scss";
5353
import { toastr } from "../../../../components/toast";
54+
import { AnalyticsEvents } from "../../../../enums";
5455

5556
type Status = "processing" | "success" | "error";
5657

@@ -115,6 +116,12 @@ const AiPaywallCompletePage = () => {
115116
React.useEffect(() => {
116117
const run = async () => {
117118
try {
119+
window.dataLayer = window.dataLayer || [];
120+
121+
window.dataLayer.push({
122+
event: AnalyticsEvents.AddPaymentMethod,
123+
});
124+
118125
setStepIndex(1);
119126

120127
await withRetry(
@@ -126,6 +133,9 @@ const AiPaywallCompletePage = () => {
126133
TOPUP_RETRY_DELAY_MS,
127134
);
128135

136+
window.dataLayer.push({
137+
event: AnalyticsEvents.WalletTopUp,
138+
});
129139

130140
if (!isWalletOnly) {
131141
await rawApiClient.instance.post(

billing/shared/top-up-balance/sub-components/TopUpButtons.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
*/
3535

3636
import React from "react";
37+
import { observer } from "mobx-react";
38+
39+
import { AnalyticsEvents } from "../../../../enums";
40+
3741
import { useCommonTranslation } from "../../../../utils/i18n";
3842

3943
import { Button, ButtonSize } from "../../../../components/button";
@@ -44,7 +48,6 @@ import { Text } from "../../../../components/text";
4448
import { useAmountValue } from "../../../wallet/context";
4549
import styles from "../styles/TopUpModal.module.scss";
4650
import { AI_TOOLS } from "../../../constants";
47-
import { observer } from "mobx-react";
4851
import { usePaymentStore } from "../../../store/PaymentStoreProvider";
4952

5053
interface TopUpButtonsProps {
@@ -72,7 +75,7 @@ const TopUpButtons: React.FC<TopUpButtonsProps> = ({
7275
onTopUpBalance,
7376
serviceName,
7477
afterTopUp,
75-
isDisabled
78+
isDisabled,
7679
}) => {
7780
const paymentStore = usePaymentStore();
7881

@@ -99,6 +102,13 @@ const TopUpButtons: React.FC<TopUpButtonsProps> = ({
99102
throw new Error(t("UnexpectedError"));
100103
}
101104

105+
if (!serviceName) {
106+
window.dataLayer = window.dataLayer || [];
107+
window.dataLayer.push({
108+
event: AnalyticsEvents.WalletTopUp,
109+
});
110+
}
111+
102112
const requests: Promise<unknown>[] = [
103113
fetchBalance!(),
104114
fetchTransactionHistory!(serviceName),

billing/store/PaymentStore.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import { makeAutoObservable, runInAction } from "mobx";
3737
import type {
3838
PaymentApi,
39+
PaymentApiGetCheckoutSetupUrlRequest,
40+
PaymentUrlRequestDto,
3941
ProfilesApi,
4042
PortalQuotaApi,
4143
CommonSettingsApi,
@@ -60,6 +62,7 @@ import { formatCurrencyValue } from "../utils/common";
6062
import { combineUrl } from "../../utils/combineUrl";
6163
import { getCookie } from "../../utils/cookie";
6264
import { LANGUAGE } from "../../constants";
65+
import { AnalyticsEvents } from "../../enums";
6366
import {
6467
AI_ENUM,
6568
BACKUP_SERVICE,
@@ -729,12 +732,17 @@ class PaymentStore {
729732
this.addAbortController(abortController);
730733

731734
const backUrl = url || `${window.location.href}?complete=true`;
735+
const successUrl = combineUrl(
736+
window.location.origin,
737+
"/portal-settings/payments/wallet?complete=true&type=wallet",
738+
);
732739

733740
try {
734741
const res = await this.paymentApi.getCheckoutSetupUrl(
735742
{
736743
backUrl,
737-
},
744+
successUrl,
745+
} as PaymentApiGetCheckoutSetupUrlRequest & { successUrl: string },
738746
{
739747
signal: abortController.signal,
740748
},
@@ -890,7 +898,11 @@ class PaymentStore {
890898
getBasicPaymentLink = async (managersCount: number) => {
891899
const backUrl = combineUrl(
892900
window.location.origin,
893-
"/portal-settings/payments/portal-payments?complete=true",
901+
"/portal-settings/payments/portal-payments?cancel=true&type=tariff",
902+
);
903+
const successUrl = combineUrl(
904+
window.location.origin,
905+
"/portal-settings/payments/portal-payments?complete=true&type=tariff",
894906
);
895907

896908
const abortController = new AbortController();
@@ -899,7 +911,11 @@ class PaymentStore {
899911
try {
900912
const res = await this.paymentApi.getPaymentUrl(
901913
{
902-
paymentUrlRequestDto: { quantity: { admin: managersCount }, backUrl },
914+
paymentUrlRequestDto: {
915+
quantity: { admin: managersCount },
916+
backUrl,
917+
successUrl,
918+
} as PaymentUrlRequestDto & { successUrl: string },
903919
},
904920
{ signal: abortController.signal },
905921
);
@@ -915,7 +931,11 @@ class PaymentStore {
915931
getPaymentLink = async (token?: AbortSignal) => {
916932
const backUrl = combineUrl(
917933
window.location.origin,
918-
"/portal-settings/payments/portal-payments?complete=true",
934+
"/portal-settings/payments/portal-payments?cancel=true&type=tariff",
935+
);
936+
const successUrl = combineUrl(
937+
window.location.origin,
938+
"/portal-settings/payments/portal-payments?complete=true&type=tariff",
919939
);
920940

921941
try {
@@ -924,7 +944,8 @@ class PaymentStore {
924944
paymentUrlRequestDto: {
925945
quantity: { admin: this.managersCount },
926946
backUrl,
927-
},
947+
successUrl,
948+
} as PaymentUrlRequestDto & { successUrl: string },
928949
},
929950
token ? { signal: token } : undefined,
930951
);
@@ -978,6 +999,17 @@ class PaymentStore {
978999
};
9791000

9801001
init = async (t: TTranslation) => {
1002+
const url = window.location.href;
1003+
if (url.includes("complete=true") && url.includes("type=tariff")) {
1004+
window.dataLayer = window.dataLayer || [];
1005+
window.dataLayer.push({
1006+
event: AnalyticsEvents.Purchase,
1007+
ecommerce: {
1008+
items: [{ item_name: "DocSpace Business" }],
1009+
},
1010+
});
1011+
}
1012+
9811013
await this.tariff.fetchCustomerInfo();
9821014

9831015
if (this.isInitPaymentPage) {
@@ -1029,7 +1061,15 @@ class PaymentStore {
10291061
};
10301062

10311063
paymentMethodInit = async (t: TTranslation, integrationUrl?: string) => {
1032-
const isRefresh = window.location.href.includes("complete=true");
1064+
const url = window.location.href;
1065+
const isRefresh = url.includes("complete=true");
1066+
1067+
if (isRefresh && url.includes("type=wallet")) {
1068+
window.dataLayer = window.dataLayer || [];
1069+
window.dataLayer.push({
1070+
event: AnalyticsEvents.AddPaymentMethod,
1071+
});
1072+
}
10331073

10341074
try {
10351075
const requests: Promise<unknown>[] = [];

enums/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,27 @@ export enum DistributedTaskStatus {
420420
Canceled,
421421
Failed,
422422
}
423+
424+
/**
425+
* Enum for GTM dataLayer analytics events.
426+
* @readonly
427+
*/
428+
export enum AnalyticsEvents {
429+
RoomCreated = "room_created",
430+
RoomDeleted = "room_deleted",
431+
RoomShared = "room_shared",
432+
RoomArchived = "room_archived",
433+
AgentCreated = "agent_created",
434+
AgentDeleted = "agent_deleted",
435+
FileCreated = "file_created",
436+
FileUploaded = "file_uploaded",
437+
FileDownloaded = "file_downloaded",
438+
FileShared = "file_shared",
439+
FileDeleted = "file_deleted",
440+
UserInvited = "user_invited",
441+
AiProviderAdded = "ai_provider_added",
442+
WalletTopUp = "wallet_topup",
443+
AddPaymentMethod = "add_payment_method",
444+
Purchase = "purchase",
445+
}
446+

types/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare global {
2+
interface Window {
3+
dataLayer?: Record<string, unknown>[];
4+
}
5+
}
6+
7+
export {};

0 commit comments

Comments
 (0)