{
  "information": {
    "Title": "xAPI_WebEJS",
    "Author": [
      "lookang"
    ],
    "AuthorLogo": [
      ""
    ],
    "Password": "unused",
    "Keywords": "",
    "Abstract": "",
    "Copyright": "",
    "Level": "",
    "Language": "",
    "Logo": [
      "./xAPI.png"
    ],
    "RunAlways": "true",
    "ModelTab": "",
    "ModelTabTitle": "",
    "ModelName": "",
    "FixedNavigationBar": "false",
    "CSSFile": "",
    "DetectedFiles": [
      "./xAPI.png"
    ],
    "AuxiliaryFiles": [
      "./xapiwrapper.min.js",
      "./xAPI.png"
    ],
    "HTMLHead": "<script src=\"xapiwrapper.min.js\"></script>\n\n <script>\n    // Using a namespace to prevent global variable clashes\n    const XAPIUtils = {\n      parameters: null, // Parameters store\n      getParameters: function () {\n        if (!this.parameters) { // Ensure fetch once\n          var urlParams = new URLSearchParams(window.location.search);\n          var endpoint = urlParams.get('endpoint');\n          var auth = urlParams.get('auth');\n          var agent = JSON.parse(urlParams.get('agent'));\n          var stateId = urlParams.get('stateId');\n          var activityId = urlParams.get('activityId');\n\n          ADL.XAPIWrapper.changeConfig({\n            \"endpoint\": endpoint + \"/\",\n            \"auth\": `Basic ${auth}`\n          });\n\n          this.parameters = {\n            agent,\n            stateId,\n            activityId\n          };\n        }\n\n        return this.parameters;\n      }\n    };\n\n    // Immediately invoke getParameters on page load\n    document.addEventListener(\"DOMContentLoaded\", function() {\n      XAPIUtils.getParameters(); // Fetch parameters once on load\n    });\n\n    function sendScore(score) {\n      try {\n        const parameters = XAPIUtils.getParameters(); // Retrieve parameters from store\n        const activityid = parameters.activityId;\n        const stateId = parameters.stateId;\n        const agent = parameters.agent;\n        const registration = null;\n\n        const stateValue = {\n          score: score\n        };\n\n        ADL.XAPIWrapper.sendState(activityid, agent, stateId, registration, stateValue);\n      } catch (err) {\n        console.error(\"An error has occurred!\", err);\n      }\n    }\n</script>\n\n<script \nasync=\"true\" src=\"https://www.googletagmanager.com/gtag/js?id=G-S9EWRY1CPJ\"></script>\n<script>\n  window.dataLayer = window.dataLayer || [];\n  function gtag(){dataLayer.push(arguments);}\n  gtag('js', new Date());\n\n  gtag('config', 'G-S9EWRY1CPJ');\n</script>",
    "SaveInXMLFormat": "false",
    "IncludeSource": "true",
    "IncludeLibrary": "true",
    "UglifyJS": "false",
    "PreviewFullModel": "false",
    "UseInterpreter": "true",
    "UseDeltaForODE": "false"
  },
  "description": {
    "pages": []
  },
  "model": {
    "variables": {
      "pages": [
        {
          "Name": "xAPI",
          "Active": "true",
          "Internal": "false",
          "Type": "undefined",
          "PageComment": "",
          "Variables": [
            {
              "Name": "totalScore",
              "Value": "0",
              "Type": "double",
              "Dimension": "",
              "Comment": "",
              "Domain": ""
            },
            {
              "Name": "",
              "Value": "",
              "Type": "double",
              "Dimension": "",
              "Comment": "",
              "Domain": ""
            }
          ]
        }
      ]
    },
    "initialization": {
      "pages": []
    },
    "evolution": {
      "information": {
        "FPS": "20",
        "SPD": "1",
        "RealTimeVariable": "",
        "Autoplay": "true"
      },
      "pages": []
    },
    "fixed_relations": {
      "pages": []
    },
    "custom": {
      "pages": [
        {
          "Name": "xAPI",
          "Active": "true",
          "Internal": "false",
          "Type": "undefined",
          "Comment": "",
          "Code": "// xAPI\nfunction getParameters() {\n  var urlParams = new URLSearchParams(window.location.search);\n  var endpoint = urlParams.get('endpoint') + \"/\";\n  var auth = urlParams.get('auth');\n\n  var actorObject = JSON.parse(urlParams.get('actor')); // this needs to be JSON decoded\n  var actor = actorObject ? actorObject.id : null;\n  var activity_id = urlParams.get('activityId'); // for example, http://adlnet.gov/expapi/activities/question/{question-id}\n\n//   document.querySelector(\"#cookieId\").innerText = \"Cookie: \" + auth;\n//   document.querySelector(\"#questionId\").innerText = \"QuestionId: \" + activity_id;\n//   document.querySelector(\"#userId\").innerText = \"UserId: \" + actor ;\n\n  var conf = {\n    \"endpoint\" : endpoint,\n    \"auth\": `Basic ${auth}`\n    ,\"withCredentials\": true\n  };\n\n  ADL.XAPIWrapper.changeConfig(conf);\n\n  return {\n    actor,\n    activity_id\n  }\n}\n\nfunction sendState(answer){\n  if (totalScore === 'randomText'){\n    totalScore = 0;\n  }\n  if(answer === 'randomText'){\n    totalScore = 'randomText';\n  } else {\n    totalScore = totalScore + answer;\n  }\n\n  try {\n    var parameters = getParameters();\n    var stateval = {\n      score: totalScore\n    };\n    ADL.XAPIWrapper.sendState(\"http://adlnet.gov/expapi/activities/question/\" + parameters.activity_id,\n        {\"mbox\":\"mailto:tom@example.com\"},\n        parameters.actor, null, stateval);\n    // document.querySelector(\"#result\").innerText = \"Score Submitted: \" + totalScore;\n  } catch (err) {\n    console.error(\"An error has occurred!\", err);\n    // document.querySelector(\"#result\").innerText = \"Error has occurred: \" + err;\n  }\n}\n"
        }
      ]
    },
    "elements": {
      "list": []
    }
  },
  "view": {
    "Tree": [
      {
        "Name": "singlePlotPanel",
        "Type": "Panel",
        "Expanded": "true",
        "Children": [
          {
            "Name": "labelPanel",
            "Type": "Panel",
            "Expanded": "true",
            "Children": [
              {
                "Name": "topLabel",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"<h1>xAPI test</h1>\""
                  }
                ]
              },
              {
                "Name": "Send_score_value_of",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"Send_score_value_of\""
                  }
                ]
              },
              {
                "Name": "button2",
                "Type": "Button",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"+2\""
                  },
                  {
                    "name": "OnClick",
                    "value": "sendState(2)"
                  },
                  {
                    "name": "Width",
                    "value": "\"30%\""
                  }
                ]
              },
              {
                "Name": "button2_2",
                "Type": "Button",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"+5\""
                  },
                  {
                    "name": "OnClick",
                    "value": "sendState(5)"
                  },
                  {
                    "name": "Width",
                    "value": "\"30%\""
                  }
                ]
              }
            ]
          },
          {
            "Name": "panel",
            "Type": "Panel",
            "Expanded": "true",
            "Properties": [
              {
                "name": "Display",
                "value": "\"block\""
              }
            ],
            "Children": [
              {
                "Name": "cookieId",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"cookieId=\""
                  },
                  {
                    "name": "Display",
                    "value": "\"block\""
                  }
                ]
              },
              {
                "Name": "QuestionId",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"QuestionId\""
                  },
                  {
                    "name": "Display",
                    "value": "\"block\""
                  }
                ]
              },
              {
                "Name": "UserId",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"UserId=\""
                  },
                  {
                    "name": "Display",
                    "value": "\"block\""
                  }
                ]
              },
              {
                "Name": "cookie",
                "Type": "Label",
                "Properties": [
                  {
                    "name": "Text",
                    "value": "\"cookie=\""
                  },
                  {
                    "name": "Display",
                    "value": "\"block\""
                  }
                ]
              }
            ]
          }
        ]
      }
    ],
    "RootProperties": []
  },
  "metadata": {
    "APP": "WebEJS",
    "CreatedWith": "WebEJS : The web version of Easy JavaScript Simulations",
    "MoreInfo": "WebEJS 1.1",
    "version": "https://www.um.es/fem/wikis/webejs/"
  }
}