11import { useCallback , useEffect , useState } from 'react' ;
22import { Linking } from 'react-native' ;
3+ import { analyticsEmitter } from '../../analytics/utils/analyticsEmitter' ;
34import { getDeferredLink } from '../api/getDeferredLink' ;
45import { resolveShortLink } from '../api/resolveShortLink' ;
56import type {
@@ -15,6 +16,7 @@ import {
1516 isInfrastructureUrl ,
1617 isWebUrl ,
1718} from '../utils/urlHelpers' ;
19+ import { OPENED_VIA_UNIVERSAL_LINK } from '../../analytics/const/definedEvents' ;
1820
1921let sessionHandled = false ;
2022
@@ -152,7 +154,15 @@ export const useDetour = ({
152154
153155 const subscription = Linking . addEventListener ( 'url' , async ( { url } ) => {
154156 const resolved = await resolveLink ( url ) ;
155- if ( resolved ) setLink ( resolved ) ;
157+ if ( resolved ) {
158+ if ( resolved . type !== 'scheme' ) {
159+ analyticsEmitter . emit ( {
160+ eventName : OPENED_VIA_UNIVERSAL_LINK ,
161+ data : { url } ,
162+ } ) ;
163+ }
164+ setLink ( resolved ) ;
165+ }
156166 } ) ;
157167 return ( ) => subscription . remove ( ) ;
158168 } , [ linkProcessingMode , resolveLink ] ) ;
@@ -175,7 +185,15 @@ export const useDetour = ({
175185 if ( initialUrl && ! isInfrastructureUrl ( initialUrl ) ) {
176186 await markFirstEntrance ( storage ) ;
177187 const resolved = await resolveLink ( initialUrl ) ;
178- if ( resolved ) setLink ( resolved ) ;
188+ if ( resolved ) {
189+ if ( resolved . type !== 'scheme' ) {
190+ analyticsEmitter . emit ( {
191+ eventName : OPENED_VIA_UNIVERSAL_LINK ,
192+ data : { url : initialUrl } ,
193+ } ) ;
194+ }
195+ setLink ( resolved ) ;
196+ }
179197 return ;
180198 }
181199 }
0 commit comments