diff --git a/src/components/TwaAnalyticsProvider.tsx b/src/components/TwaAnalyticsProvider.tsx index dcc9376..1ff8551 100755 --- a/src/components/TwaAnalyticsProvider.tsx +++ b/src/components/TwaAnalyticsProvider.tsx @@ -302,6 +302,8 @@ const TwaAnalyticsProvider: FunctionComponent = ({ const originalSwitchInlineQuery = webApp.switchInlineQuery; const originalOpenInvoice = webApp.openInvoice; const originalShareToStory = webApp.shareToStory; + const originalOpenLink = webApp.openLink; + const originalOpenTelegramLink = webApp.openTelegramLink; webApp.close = () => { eventBuilder.track(EventType.SessionEnd, { @@ -389,6 +391,26 @@ const TwaAnalyticsProvider: FunctionComponent = ({ return originalShareToStory.call(webApp, media_url, params); }; + webApp.openLink = (url: string, options?: any) => { + eventBuilder.track(`${EventType.OpenLink}: ${url}`, { + url: url, + options: options, + timestamp: Date.now(), + }); + + return originalOpenLink.call(webApp, url, options); + }; + + webApp.openTelegramLink = (url: string, options?: any) => { + eventBuilder.track(`${EventType.OpenTgLink}: ${url}`, { + url: url, + options: options, + timestamp: Date.now(), + }); + + return originalOpenTelegramLink.call(webApp, url, options); + }; + return () => { // Restore original methods on cleanup webApp.close = originalClose; diff --git a/src/enum/event-type.enum.ts b/src/enum/event-type.enum.ts index f71135c..9889aa2 100755 --- a/src/enum/event-type.enum.ts +++ b/src/enum/event-type.enum.ts @@ -37,6 +37,8 @@ export enum EventType { ShareToStory = 'Story shared', SessionStart = 'Session start', SessionEnd = 'Session end', + OpenLink = 'Link opened', + OpenTgLink = 'Telegram link opened', // Wallet events Wallet = 'Wallet', diff --git a/src/telegram/web-app.d.ts b/src/telegram/web-app.d.ts index 82c711f..bbcf9fa 100755 --- a/src/telegram/web-app.d.ts +++ b/src/telegram/web-app.d.ts @@ -182,7 +182,7 @@ export declare namespace Telegram { // Link handling openLink: (url: string, options?: { try_instant_view?: boolean }) => void; - openTelegramLink: (url: string) => void; + openTelegramLink: (url: string, options?: { try_instant_view?: boolean }) => void; // Invoice methods openInvoice: (url: string, callback?: any) => Promise<{