JavaScript To Transfer Custom Variables From Storyline Into WordPress
let player = GetPlayer(); player.SetVar("SL_ID",document.title); let fields = { STORYLINE_VARIABLE_NAME: '', }; let data = {}; handleForm(data, fields, player); } function handleForm(data, fields, player) { for (let [key, val] of Object.entries(fields)) { let value = player.GetVar(key); if( value ) { data[key] = value; } } data.action = 'save_user_data_json'; data.title = document.title; var pathArray = window.location.pathname.split('/'); data.sl_name = pathArray[3]; let url = window.location.origin + '/wp-admin/admin-ajax.php'; fetch(url, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Cache-Control': 'no-cache', }, body: new URLSearchParams( data ) }).then(response => response.json()) .then(response => console.log(response.message)) .catch(err => console.log(err));
JavaScript To Transfer Stored User Variables From WordPress Into Storyline
var sluser = window.parent.userCode; fetch ('/wp-content/uploads/jsons/results_' + sluser + '.json'). then (response => { return response.json (); }).then (data => { var player = GetPlayer(); player.SetVar("STORYLINE_VARIABLE_NAME", data.SL##_VARIABLENAME); }). catch (err => { console.log ("No Data Available.") });
Shortcode For Displaying User Variables On Any WordPress Post/Page
[ storyline_user_data options="VARIABLE-NAME" ]
Optional: Add an additional user=”USERNAME” value to your shortcode if you wish to display the stored variable for a particular user.
E.g.
[ storyline_user_data user="johnsmith" options="VARIABLE-NAME" ]
Shortcode For Creating A Leaderboard Using Any Numeric Variable
[ sl_leaderboard variable="VARIABLE-NAME" ]