How to save information about users and use it later in the intervention

From Lifeguide Wiki
Jump to: navigation, search

Saved information can be used in many ways:

  • to display the responses end-users gave to an interaction
  • to display the original page so end-users can see how they responded to an interaction and then change their answer
  • to provide feedback based on their responses, e.g. a score for a quiz

End-users must have created an account in order for their responses to be saved to their username.

To save responses, the commands save and savevalue are used. To load/display responses that you have saved, the commands, load and loadvalue are used. The command saveandload is used to display responses when end-users are re-shown the same page.

savevalue

The savevalue command allows you to save a variable for a user that can then be loaded again in later sessions.

You can use it to:

  • save the group that users have been randomised to:

savevalue(username, "group", "web")

  • save the time users have seen a particular page:

savevalue(username, "s1time", currenttime())

  • save the response users have given to a single, multiple-choice, text-entry or numeric interaction:

savevalue(username, "fatigue", page1.interaction1)

N.B. You must use a Next type button on the page that you are saving information from when you use savevalue. If you use a Jump button, the logic referring to savevalue will not be read and so the variable will not save.

save

The save key command allows you to save the responses that an end-user enters on a page. This can then be loaded using the load key command onto another page to re-show it to your end-user. The save and load commands can be used across sessions and requires end-users to have registered a user account.

Example:

show page1

save page1 for username

Then, later on in the logic (either in the same session or a later session) the following logic would be used:

show page20

set default page20.interaction2 to load page1.interaction1 for username

So, in the first part of this logic page1 is saved for the end-user. Then when they get to page20 in the intervention the response that they entered on interaction1 on page1 will be reshown to them on interaction2 on page20.


saveandload

This key command can be used after a page that includes interactions so that if an end-user moves away from that page and then comes back to it, the page will automatically show them what they entered the last time they were on that page. This line of logic would simply be written as so:

show page1

saveandload page1 for username

Any interaction on page1 would then be saved and loaded each time the end-user comes back to that page.

Showing users' responses on a new page

An example is to re-show a goal that an end-user has entered in a previous session so that they can say whether they achieved it.

First you will need to create a single/multiple-choice/numeric interaction or a text-entry box on a page and give it a unique name. Then in the intervention.lgil file, write the logic to save the goal the response that users will enter:

show session1page1

savevalue(username, "goal1", session1page1.interaction1)

The logic above is saving interaction1 on page1 as a variable called goal1

To show the goal on a page in a different session, you will need to create a new page, insert a text box and set the text as a printed variable. Click here for instructions on how to set text as a printed variable

Once you have set the text as a variable, you will need to add the following logic to the intervention.lgil file,:

show session2page2

set session2page1.s1goal to loadvalue(username,"goal1")

The above logic will load the goal that was saved as goal1 previously in the logic, into the text box with the variable name s1goal on session2page2 .


If you are displaying this goal with other goals as feedback, please note there are a few extra steps:

1) You may need to use a container on session2page1. Please click on the Containers link at the bottom of the page for more information on this.

2) The text that you have just set as a variable will need to be set to feedback. First, click on the text box. Under Textbox properties scroll down to the end and select Feedback. Enter a unique name (e.g. goal_one)

3) You will need an extra line of logic telling the goal to show only if a goal has been previously entered by an end-user:

show session2page1.s1_goal if (not(isempty (loadvalue(username,"goal1"))))

This logic will show the feedback item called s1_goal on session2page1 if goal1 is not empty (i.e. if an end-user entered a goal which was saved as goal1)