Skip to content

Commit

Permalink
feat: oaid ping for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
CarinaDraganJW committed May 17, 2023
1 parent 70c96a5 commit b9f3991
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
7 changes: 6 additions & 1 deletion public/jwpltx.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ 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;
uri.fed = fed;
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');
Expand Down
10 changes: 9 additions & 1 deletion src/hooks/useOttAnalytics.ts
Original file line number Diff line number Diff line change
@@ -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<jwplayer.JWPlayer | null>(null);

const decodedToken: DecodedJwtToken | undefined = isLoggedIn ? jwtDecode(auth?.jwt) : undefined;

const timeHandler = useCallback(({ position, duration }: jwplayer.TimeParam) => {
window.jwpltx.time(position, duration);
}, []);
Expand All @@ -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(() => {
Expand Down
21 changes: 21 additions & 0 deletions types/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion types/jwpltx.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit b9f3991

Please sign in to comment.