Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The LSDK sample demonstrates how to send Motive Insights data using the LSDK Reporter.

    void Start()
    {
        Reporter.Instance.ApplicationStart();

        if (LaunchInput)
        {
            LaunchInput.SetActive(false);
        }

        if (SessionScreen)
        {
            SessionScreen.SetActive(false);
        }

        StartCoroutine(WaitAppReady());
    }

On start we send the Application Start report and disable the screens in the sample app. Start a Coroutine that waits for the Launch Service to be ready.

    private IEnumerator WaitAppReady()
    {
        while (!AppSetup.Instance.IsReady)
        {
            yield return null;
        }

        AppReady();
    }

Polls the IsReady flag on AppSetup to ensure the LSDK has completed its configuration.

    void AppReady()
    {
        if (!LaunchSessionManager.Instance.IsSessionReady)
        {
            if (LaunchInput)
            {
                LaunchInput.SetActive(true);
            }

            StartCoroutine(WaitSessionReady());
        }
        else
        {
            SessionReady();
        }
    }

Once the app has completed configuration, it will either have a configured session (meaning you can start sending reporting data), or will need to initiate a session with a Launch Code. Note that apps Launched From Launch Pad will have a configured session. In this case, if there is no session, we display the Launch Input screen to collect a Launch Code from the user. We start a Coroutine that waits for the session to be ready.

    IEnumerator WaitSessionReady()
    {
        while (!LaunchSessionManager.Instance.IsSessionReady)
        {
            yield return null;
        }

        SessionReady();
    }

Poll IsSessionReady.

    public void SubmitLaunchCode(string launchCode)
    {
        LaunchSessionManager.Instance.GetLaunchSession(launchCode, info =>
        {
            LaunchSessionManager.Instance.ConfigureLaunchSession(info);
        },
        status =>
        {
            Debug.LogError($"Failed to get launch session: {status}");
        });
    }

This code shows how to submit a Launch Code entered by the user to Launch Server and how to configure the Session. Again, this code should not be required for apps launched directly via Launch Pad, but is useful for testing.

    void SessionReady()
    {
        Debug.Log("Session Ready");

        Reporter.Instance.StartSession();
        Reporter.Instance.ScenarioStarted("my_scenario", "Test Scenario");

        if (LaunchInput)
        {
            LaunchInput.SetActive(false);
        }

        if (SessionScreen)
        {
            SessionScreen.SetActive(true);
        }
    }

When the session is ready, send the Start Session and Scenario Started reports. Hide the Launch Input screen and show the Session Screen. The Session Screen is a simple UI that allows you to test various pre-configured Reporter messages.

It is crucial to send the Start Session and Scenario Started reports at the beginning of a Scenario in order for the Insights pane to interpret the data.

    public void AssessmentScore(float score)
    {
        Reporter.Instance.AssessmentScore("score_id", "Score Assessment", "A score assessment", score, 100f);
    }

    public void AssessmentCompletion(bool complete)
    {
        Reporter.Instance.AssessmentCompletion("completion_id", "Completion Assessment", "A completion assessment", complete);
    }

    public void AssessmentSuccess(bool pass)
    {
        Reporter.Instance.AssessmentSuccess("pass_fail_id", "Pass/Fail Assessment", "A pass/fail assessment", pass);
    }

    public void ScenarioResult1()
    {
        Reporter.Instance.ScenarioResult(75, 100, true, true);
    }

    public void ScenarioResult2()
    {
        Reporter.Instance.ScenarioResult(45, 100, false, false);
    }

    public void EndScenario()
    {
        Reporter.Instance.ScenarioEnded();
    }

Reports that can be generated by Launch Server:

Assessments

Assessments are collected by Insights for specific tasks within the context of a Scenario. Note that these do not map to the final Scenario results that are sent to SCORM. Scenario Result is described in the next section.

  • Score: A scaled score (i.e. 8/10)

  • Completion: Whether the learner completed a task

  • Success: pass/fail for a task

Scenario Result

This reports the overall result for a Scenario. It includes the same properties as assessments, but grouped together in a single message. These results can be reported back to an LMS via SCORM.

   public void TakePicture()
    {
        if (PhotoRenderTexture == null)
        {
            throw new InvalidOperationException("Photo render texture must be set.");
        }

        var prev = RenderTexture.active;

        RenderTexture.active = PhotoRenderTexture;
        Texture2D tex = new Texture2D(PhotoRenderTexture.width, PhotoRenderTexture.height, TextureFormat.RGB24, false);
        tex.ReadPixels(new Rect(0, 0, PhotoRenderTexture.width, PhotoRenderTexture.height), 0, 0);

        RenderTexture.active = prev;

        var bytes = tex.EncodeToPNG();

        LaunchSessionManager.Instance.UploadMedia(bytes, "image/png", (status, media) =>
        {
            if (status == Motive.Core.Net.AuthenticatorCallStatus.Success)
            {
                Reporter.Instance.MediaInteracted(media);
            }
            else
            {
                Debug.LogError("Failed to upload media");
            }
        });
    }

Example code for uploading an image file taken from a screen grab in the app. This is reported to Launch and viewable in Insights.

    void OnApplicationPause(bool isPaused)
    {
        Reporter.Instance.ApplicationPause(isPaused);
    }

    private void OnApplicationQuit()
    {
        Reporter.Instance.EndSession();
        Reporter.Instance.ApplicationQuit();
    }

Additional reporting on pause/shutdown.

  • No labels