Callbacks
Introduction
why callbacks? the socratease sdk loads a ui and, based on user interaction, modifies the ui for example, imagine you load the quiz ui and a user answers the quiz and then submits it by default, the user will see a summary as shown below but instead of showing this page, maybe you want to redirect a user to a different url to override this default behavior, socratease allows you to use callbacks how does it work let's consider the previous example if a user clicks the submit button on a quiz, you want to intercept it and perform some action for this, you need to know that there is an event called unit submitted see the code below there is the regular socratease init function, which you would include by default just below that, we have a socratease callback function, which is meant for these interceptions imagine you want to redirect the user to google com if they finished the quiz you could check for the event type and if it qualifies, just write regular js code to carry out the redirection //make sure to add this code inside onload event socratease init(clientid, jsonpayload, hmacpayloadb64, options); socratease callback = (type, resp, fallback) => { if (type === "unit submitted") { window\ location href = "https //google com"; } else { fallback( resp); } }; callback parameters the callback is a function of these parameters type actions like quiz submission or quiz creation generate a unique event name that you can identify by type to override the default behavior in this way, you can just write multiple if else conditions and override behavior or each action resp often, you would want the post callback behaviour to depend on what the user did before the callback for example, you would like to redirect the user to different pages based on the percentage they scored resp contains this information as list of dictionaries fallback fallback is basically the default behaviour of an action for example, if you don't want to modify the navigation flow of a high scoring user, you will call fallback( resp) within an if condition for that user you should always make the fallback explicit in the example above, if the callback type is not unit submitted , we have explicitly written that fallback( reso) should be called otherwise, for example, if the event type is unit created as the if condition isn't satisfied, nothing will happen as fallback( resp) isn't being called event types you can find the list of all events in the events article within this help folder in the sidebar to your left