Skip to content

Commit

Permalink
Merge pull request #65 from ajinkyapandetekdi/latest-all-0.5
Browse files Browse the repository at this point in the history
Bug #204894 [ALL] React APP Telemetry not working for root url for
  • Loading branch information
gouravmore authored Sep 18, 2023
2 parents 69597aa + 2c25383 commit f2d21de
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 45 deletions.
31 changes: 16 additions & 15 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,6 +24,7 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
import StartLearn4 from './pages/PlayAndLearn/StartLearn';

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

useEffect(() => {
Expand All @@ -32,12 +34,11 @@ function App() {
const { visitorId } = await fp.get();

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

setFp();
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 +74,21 @@ function App() {
// tslint:disable-next-line:max-line-length
metadata: {},
});
};
initService();
if (!ranonce) {

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

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

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

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

return (
<HashRouter>

return (
<>
<Link to={'/exploreandlearn/score'} id="link_score_proto3" className="hide">
score
</Link>
Expand All @@ -125,7 +126,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
8 changes: 4 additions & 4 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('DT');
interactCall("playAudio", "startlearn","DT", "play");
set_temp_audio(new Audio(content[sel_lang].audio));
};
// console.log(isAudioPlay);

const pauseAudio = () => {
interactCall('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('DT');
interactCall("learnAudio", "startlearn","DT", "learn");
setFlag(!flag);
temp_audio.addEventListener('ended', () => setFlag(true));
}
Expand All @@ -49,7 +49,7 @@ function StartLearn() {
};

const newSentence = () => {
interactCall('DT');
interactCall("newSentence", "startlearn","DT", "");
handleChangeWord()
};
useEffect(() => {
Expand Down
12 changes: 6 additions & 6 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('DT');
interactCall("playAudio", "score","DT", "play");
set_temp_audio(new Audio(recordedAudio));
};
const pauseAudio = () => {
interactCall('DT');
interactCall("pauseAudio", "startlearn","DT", "pause");
if (temp_audio !== null) {
temp_audio.pause();
setFlag(!false);
Expand All @@ -82,11 +82,11 @@ function Score() {
};

const newSentence = () => {
interactCall('DT');
interactCall("newSentence", "startlearn","DT", "");
navigate(-1);
};
const trySameSentence = () => {
interactCall('DT');
interactCall("trySameSentence", "startlearn","DT", "");
localStorage.setItem('trysame', 'yes');
navigate(-1);
};
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
6 changes: 3 additions & 3 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('DT');
interactCall("playAudio", "score","DT", "play");
set_temp_audio(new Audio(content[sel_lang].audio));
};

const pauseAudio = () => {
interactCall('DT');
interactCall("pauseAudio", "score","DT", "pause");
if (temp_audio !== null) {
temp_audio.pause();
setFlag(!false);
Expand All @@ -55,7 +55,7 @@ function StartLearn() {
};

const newSentence = () => {
interactCall('DT');
interactCall("newSentence", "score","DT", "");
handleChangeWord()
};

Expand Down
10 changes: 6 additions & 4 deletions src/services/callTelemetryIntract.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import { interact,start } from '../services/telementryService';
const duration = new Date().getTime();
export const interactCall = (telemetryMode) => {
interact(telemetryMode)

export const interactCall = (id, uri, telemetryMode, currentPage) => {
interact(id, uri, telemetryMode, currentPage)
};

export const startEvent=()=>{
export const startEvent=(pageUrl)=>{
start(
duration
duration,
pageUrl
);
}
15 changes: 7 additions & 8 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,23 +87,24 @@ 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',
},
});
};

export const interact = (telemetryMode) => {

export const interact = (id, url, telemetryMode, currentPage) => {
if (checkTelemetryMode(telemetryMode)) {
CsTelemetryModule.instance.telemetryService.raiseInteractTelemetry({
options: getEventOptions(),
edata: { type: 'TOUCH', subtype: '', pageid: url },
edata: { type: "TOUCH", id: id, pageid: url, subtype: currentPage || "" },
});
}
};
Expand Down

0 comments on commit f2d21de

Please sign in to comment.