From b9f3991b0436a25eb49aef6bde46f77e8651f419 Mon Sep 17 00:00:00 2001 From: Carina Dragan Date: Wed, 17 May 2023 14:46:09 +0200 Subject: [PATCH] feat: oaid ping for analytics --- public/jwpltx.js | 7 ++++++- src/hooks/useOttAnalytics.ts | 10 +++++++++- types/account.d.ts | 21 +++++++++++++++++++++ types/jwpltx.d.ts | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/public/jwpltx.js b/public/jwpltx.js index 6aa1331b6..2399e0ae6 100644 --- a/public/jwpltx.js +++ b/public/jwpltx.js @@ -90,7 +90,7 @@ window.jwpltx = window.jwpltx || {}; } // Process a player ready event - o.ready = function (aid, bun, fed, id, t) { + o.ready = function (aid, bun, fed, id, t, oaid) { uri = JSON.parse(JSON.stringify(URI)); uri.aid = aid; uri.bun = bun; @@ -98,6 +98,11 @@ window.jwpltx = window.jwpltx || {}; uri.id = id; uri.t = t; + // Send oaid only for logged in users + if (oaid) { + uri.oaid = oaid; + } + uri.emi = generateId(12); uri.pli = generateId(12); sendData('e'); diff --git a/src/hooks/useOttAnalytics.ts b/src/hooks/useOttAnalytics.ts index 2b88c2030..97b2b1594 100644 --- a/src/hooks/useOttAnalytics.ts +++ b/src/hooks/useOttAnalytics.ts @@ -1,12 +1,20 @@ import { useCallback, useEffect, useState } from 'react'; +import jwtDecode from 'jwt-decode'; import type { PlaylistItem } from '#types/playlist'; import { useConfigStore } from '#src/stores/ConfigStore'; +import { useAccountStore } from '#src/stores/AccountStore'; +import type { DecodedJwtToken } from '#types/account'; const useOttAnalytics = (item?: PlaylistItem, feedId: string = '') => { const analyticsToken = useConfigStore((s) => s.config.analyticsToken); + const auth = useAccountStore((state) => state.auth); + const isLoggedIn = !!auth; + const [player, setPlayer] = useState(null); + const decodedToken: DecodedJwtToken | undefined = isLoggedIn ? jwtDecode(auth?.jwt) : undefined; + const timeHandler = useCallback(({ position, duration }: jwplayer.TimeParam) => { window.jwpltx.time(position, duration); }, []); @@ -26,7 +34,7 @@ const useOttAnalytics = (item?: PlaylistItem, feedId: string = '') => { return; } - window.jwpltx.ready(analyticsToken, window.location.hostname, feedId, item.mediaid, item.title); + window.jwpltx.ready(analyticsToken, window.location.hostname, feedId, item.mediaid, item.title, decodedToken?.tid); }, [item]); const completeHandler = useCallback(() => { diff --git a/types/account.d.ts b/types/account.d.ts index 97f82b60c..d6db72eae 100644 --- a/types/account.d.ts +++ b/types/account.d.ts @@ -3,12 +3,33 @@ import type { SerializedFavorite } from './favorite'; import type { Config } from '#types/Config'; +type UserRole = 'inplayer' | 'merchant' | 'consumer' | 'master' | 'follower' | 'admin' | undefined; + +type Scope = 'inheritance' | 'email_inheritance' | undefined; + export type AuthData = { jwt: string; customerToken: string; refreshToken: string; }; +export type DecodedJwtToken = { + aid: number; + aud: string; + ctx: UserRole[]; + exp: number; + iat: number; + jti: string; + mid: number; + mui: string; + nbf: number; + oid: number; + scopes: Scope[]; + sub: string; + tid: number; + tuuid: string; +}; + export type JwtDetails = { customerId: string; exp: number; diff --git a/types/jwpltx.d.ts b/types/jwpltx.d.ts index f08fc7474..871261079 100644 --- a/types/jwpltx.d.ts +++ b/types/jwpltx.d.ts @@ -1,5 +1,5 @@ interface Jwpltx { - ready: (analyticsId: string, hostname: string, feedid: string, mediaid: string, title: string) => void; + ready: (analyticsId: string, hostname: string, feedid: string, mediaid: string, title: string, appAccountId?: number) => void; adImpression: () => void; seek: (offset: number, duration: number) => void; seeked: () => void;