Skip to content

Commit

Permalink
Merge pull request #4 from TON-Commerce/release/v1.0.3
Browse files Browse the repository at this point in the history
Release/v1.0.3
  • Loading branch information
strd0x authored Dec 21, 2023
2 parents 605d367 + 65dc9f8 commit 6ee10cc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonsolutions/analytics-react",
"version": "1.0.3",
"version": "1.0.4",
"main": "./lib/index.сjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/builders/event.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../constants';
import { EventType } from '../enum/event-type.enum';
import { EventPushHandler } from '../event-push-handler';
import { getCurrentUTCTimestamp } from '../helpers/date.helper';
import { encryptMessage } from '../helpers/encryption.helper';
import { IEventBuilder } from '../interfaces';
import { TelegramWebAppData } from '../models';
Expand Down Expand Up @@ -115,6 +116,7 @@ export class EventBuilder implements IEventBuilder {
async track(
eventName: string,
eventProperties: Record<string, any>,
sessionIdentifier?: string,
): Promise<void> {
if (eventName === null) {
throw new Error('Event name is not set.');
Expand Down Expand Up @@ -147,9 +149,10 @@ export class EventBuilder implements IEventBuilder {
this.data.platform,
this.data.chat_type || 'N/A',
this.data.chat_instance || '0',
Math.floor(Date.now() / 1000).toString(),
getCurrentUTCTimestamp(),
eventName.startsWith(DEFAULT_SYSTEM_EVENT_PREFIX),
eventProperties.wallet || undefined,
sessionIdentifier,
);

return this.pushHandler.push(event);
Expand Down
11 changes: 8 additions & 3 deletions src/components/TwaAnalyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { EventBuilder } from '../builders';
import { loadTelegramWebAppData } from '../telegram/telegram';
import { TonConnectStorageData } from '../models/tonconnect-storage-data';
import { EventType } from '../enum/event-type.enum';
import { getCurrentUTCTimestamp } from '../helpers/date.helper';

export type TwaAnalyticsProviderOptions = {
projectId: string;
Expand Down Expand Up @@ -62,9 +63,13 @@ const TwaAnalyticsProvider: FunctionComponent<TwaAnalyticsProviderProps> = ({

useEffect(() => {
const locationPath = location.pathname;
eventBuilder.track(`${EventType.PageView} ${locationPath}`, {
path: locationPath,
});
eventBuilder.track(
`${EventType.PageView} ${locationPath}`,
{
path: locationPath,
},
getCurrentUTCTimestamp(),
);
}, []);

useEffect(() => {
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/date.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getCurrentUTCTimestamp = (): string => {
return Math.floor(Date.now() / 1000).toString();
};
1 change: 1 addition & 0 deletions src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface BaseEvent {
timestamp: string;
isAutocapture: boolean;
wallet: string | undefined;
sessionIdentifier?: string;
}
2 changes: 2 additions & 0 deletions src/utils/create-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const createEvent = (
timestamp: string,
isAutocapture: boolean,
wallet: string | undefined,
sessionIdentifier?: string,
): BaseEvent => {
return {
eventType: eventName,
Expand All @@ -27,5 +28,6 @@ export const createEvent = (
timestamp,
isAutocapture,
wallet,
sessionIdentifier,
};
};

0 comments on commit 6ee10cc

Please sign in to comment.