submit user data in all games
This commit is contained in:
@@ -91,10 +91,12 @@ import Layout from "../../layouts/Layout.astro";
|
||||
</Layout>
|
||||
<script is:inline>
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const paramsID = params.get('id');
|
||||
const gameId = params.get('id');
|
||||
const userId = params.get('userid');
|
||||
let startTime = Date.now();
|
||||
let gameData = null;
|
||||
|
||||
fetch(`https://game-du.teachertrainingkolkata.in/items/tick_phonics_option_6/${encodeURIComponent(paramsID)}?filter[status][_eq]=published`)
|
||||
fetch(`https://game-du.teachertrainingkolkata.in/items/tick_phonics_option_6/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
gameData = data.data;
|
||||
@@ -145,14 +147,12 @@ import Layout from "../../layouts/Layout.astro";
|
||||
let url = window.location.href;
|
||||
let urlSplit = url.split('/');
|
||||
let gameName = urlSplit[3] + '-' + urlSplit[4];
|
||||
let formatedDateTime;
|
||||
|
||||
window.onload = function () {
|
||||
let currentTime = new Date();
|
||||
formatedDateTime = currentTime.toLocaleString();
|
||||
};
|
||||
|
||||
function saveUserData() {
|
||||
const endTime = Date.now();
|
||||
const timeDifference = endTime - startTime;
|
||||
const timeDifferenceInSeconds = timeDifference / 1000;
|
||||
|
||||
// Get checkbox values and corresponding elements
|
||||
const checkboxes = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
|
||||
const checkboxValues = checkboxes.map(id => {
|
||||
@@ -175,13 +175,14 @@ import Layout from "../../layouts/Layout.astro";
|
||||
|
||||
// Move the userData object creation inside the saveUserData function if needed
|
||||
let userData = {
|
||||
'user': 'tick-v1@beanstalkedu.com',
|
||||
'game_name': gameName,
|
||||
'starts': formatedDateTime,
|
||||
'score': totalPoints, // Include the totalPoints in the userData
|
||||
'gameName': gameName,
|
||||
'gameID': gameId,
|
||||
'userId': userId,
|
||||
'gameTime': timeDifferenceInSeconds,
|
||||
'score': totalPoints,
|
||||
};
|
||||
console.log(userData);
|
||||
fetch(`https://2016.dev2-cs.siliconpin.com/save/`, {
|
||||
fetch(`https://phaser-game-api.s38.siliconpin.com/save-data`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
Reference in New Issue
Block a user