Skip to content

Commit

Permalink
Bug #204894 [ALL] React APP Telemetry not working for root url
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyapandetekdi committed Sep 18, 2023
1 parent 2efaeac commit 457edcf
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 34 deletions.
30 changes: 18 additions & 12 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Routes,
Route,
Link,
useLocation,
} from 'react-router-dom';
import { initialize, end } from './services/telementryService';
import '@project-sunbird/telemetry-sdk/index.js';
Expand All @@ -23,21 +24,25 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
import StartLearn4 from './pages/PlayAndLearn/StartLearn';

function App() {
const location = useLocation();
let ranonce = false;



useEffect(() => {
const setFp = async () => {
const fp = await FingerprintJS.load();

const { visitorId } = await fp.get();

localStorage.setItem('did', visitorId);
initService();
};

setFp();
const initService = () => {


const initService = () => {
if (localStorage.getItem('fpDetails_v2') !== null) {
let fpDetails_v2 = localStorage.getItem('fpDetails_v2');
var did = fpDetails_v2.result;
Expand Down Expand Up @@ -73,21 +78,22 @@ function App() {
// tslint:disable-next-line:max-line-length
metadata: {},
});
};
initService();
if (!ranonce) {

if (localStorage.getItem('contentSessionId') === null) {
startEvent();
if (!ranonce) {

if (localStorage.getItem('contentSessionId') === null) {
startEvent(location.pathname);
}
ranonce = true;
}
};


ranonce = true;
}
}, []);
useEffect(() => {
const cleanup = () => {
if (localStorage.getItem('contentSessionId') === null) {
end();
end(location.pathname);
}
};

Expand All @@ -98,9 +104,9 @@ function App() {
};
}, []);

return (
<HashRouter>

return (
<>
<Link to={'/exploreandlearn/score'} id="link_score_proto3" className="hide">
score
</Link>
Expand All @@ -125,7 +131,7 @@ function App() {
<Route path={'/playandlearn/startlearn'} element={<StartLearn4/>} />
</Routes>
<Dots />
</HashRouter>
</>
);
}

Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import * as ReactDOM from 'react-dom/client';
import App from './App';
import * as serviceWorker from './serviceWorker';

import "./index.css";
import './index.css';
import { HashRouter } from 'react-router-dom';

const container = document.getElementById('root');
const root = ReactDOM.createRoot(container);

root.render(
<>
<ColorModeScript />
<App />
<HashRouter>
<ColorModeScript />
<App />
</HashRouter>
</>
);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/ExploreAndLearn/Score/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ function Score() {
>
{isFeedbackDone === true ? (
<>
<img
{/* <img
style={{ marginRight: '40px' }}
src={Thumbs_up}
alt="thumbs-up-dis"
/>
<img src={Thumbs_Down} alt="thumbs-down-dis" />
<img src={Thumbs_Down} alt="thumbs-down-dis" /> */}
</>
) : (
<>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ExploreAndLearn/StartLearn/StartLearn.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function StartLearn() {
const [temp_audio, set_temp_audio] = useState(null);
const [flag, setFlag] = useState(true);
const playAudio = () => {
interactCall("playAudio", "startlearn","DT", "");
interactCall("playAudio", "startlearn","DT", "play");
set_temp_audio(new Audio(content[sel_lang].audio));
};
// console.log(isAudioPlay);

const pauseAudio = () => {
interactCall("pauseAudio", "startlearn","DT", "");
interactCall("pauseAudio", "startlearn","DT", "pause");
if (temp_audio !== null) {
temp_audio.pause();
setFlag(!false);
Expand All @@ -37,7 +37,7 @@ function StartLearn() {
const learnAudio = () => {
if (temp_audio !== null) {
temp_audio.play();
interactCall("learnAudio", "startlearn","DT", "");
interactCall("learnAudio", "startlearn","DT", "learn");
setFlag(!flag);
temp_audio.addEventListener('ended', () => setFlag(true));
}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/PlayAndLearn/Score.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function Score() {

const [temp_audio, set_temp_audio] = useState(null);
const playAudio = () => {
interactCall("playAudio", "score","DT", "");
interactCall("playAudio", "score","DT", "play");
set_temp_audio(new Audio(recordedAudio));
};
const pauseAudio = () => {
interactCall("pauseAudio", "startlearn","DT", "");
interactCall("pauseAudio", "startlearn","DT", "pause");
if (temp_audio !== null) {
temp_audio.pause();
setFlag(!false);
Expand Down Expand Up @@ -584,12 +584,12 @@ function Score() {
>
{isFeedbackDone === true ? (
<>
<img
{/* <img
style={{ marginRight: '40px' }}
src={Thumbs_up}
alt="thumbs-up-dis"
/>
<img src={Thumbs_Down} alt="thumbs-down-dis" />
<img src={Thumbs_Down} alt="thumbs-down-dis" /> */}
</>
) : (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/PlayAndLearn/StartLearn.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ function StartLearn() {
const location = useLocation();

const playAudio = () => {
interactCall("playAudio", "score","DT", "");
interactCall("playAudio", "score","DT", "play");
set_temp_audio(new Audio(content[sel_lang].audio));
};

const pauseAudio = () => {
interactCall("pauseAudio", "score","DT", "");
interactCall("pauseAudio", "score","DT", "pause");
if (temp_audio !== null) {
temp_audio.pause();
setFlag(!false);
Expand Down
5 changes: 3 additions & 2 deletions src/services/callTelemetryIntract.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export const interactCall = (id, uri, telemetryMode, currentPage, ) => {
interact(id, uri, telemetryMode, currentPage)
};

export const startEvent=()=>{
export const startEvent=(pageUrl)=>{
start(
duration
duration,
pageUrl
);
}
10 changes: 4 additions & 6 deletions src/services/telementryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ if (localStorage.getItem('contentSessionId') !== null) {
localStorage.setItem('allAppContentSessionId', contentSessionId);
}

let getUrl = window.location.href;
url = getUrl && getUrl.includes('#') && getUrl.split('#')[1].split('/')[1];

export const initialize = ({ context, config, metadata }) => {
context = context;
Expand Down Expand Up @@ -65,13 +63,13 @@ export const initialize = ({ context, config, metadata }) => {
}
};

export const start = duration => {
export const start = (duration, stageId) => {
CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({
options: getEventOptions(),
edata: {
type: 'content',
mode: 'play',
stageid: url,
pageid: stageId,
duration: Number((duration / 1e3).toFixed(2)),
},
});
Expand All @@ -89,12 +87,12 @@ export const response = (context, telemetryMode) => {

};

export const end = () => {
export const end = (pageUrl) => {
CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: url,
pageid: pageUrl,
summary: [],
duration: '000',
},
Expand Down

0 comments on commit 457edcf

Please sign in to comment.