Populating a [[U0]] session tag with a javascript/jquery based value

Options
I'm working on a donation form in Luminate. The donation form is being iframed into a pagebuilder page that contains some imagery and brand messaging.


Currently, I have a URL variable that's get passed to the donation form. Then, within the donation form there is an AJAX call being made against that variable that returns an array of data. This is allowing me to pre-populate a lot of the form fields for the constituent ahead of time. This all works wonderfully within the iframe.


I've now been asked to surface that constituents first name into the parent page that houses the iframe. I can't do this with the S-tag that calls first name because these constituents aren't logged in and some may not even have a constituent record to begin with,


At this point I've tried putting an onload function call on the iframe so that my parent page function will only run once the iframe finishes loading. This doesn't because the AJAX call still hasn't completed and the function returns an undefined value. I've tried setting an HTML5 local storage variable within the iframe and trying to access it from the parent page. Same issue, when the script runs in the parent page the value hasn't yet been returned by the AJAX call resulting in an undefined value.


I then started wondering could I just pass my name variable through a [[U0]] tag? Let's say I've stored my first name value as "fName". I've attempted to set that value in this fashion...


[[U0:testVar=fName]]


But then realized of course it's just going to house that in plain text, not actually referencing my variable value.


Documentation on these tags is sparse to non-existent. Anyone ever tried to do a session var with a javascript based value before?
Tagged:

Comments

  • Would still be curious if in practice you can initialize a [[U0]] value with JS, but I arrived at a solution outside of the Luminate tags.


    In the unlikely event someone else encounters a similar issue I used postMessage() an HTML5 API to transfer my variable from the donation form back to the parent page.

    https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage


    In the event anyone cares to read up on it. Let's you speak between iframe and parent page on the same domain OR on different domains. Depending on your use case it could be pretty useful, particularily with those who embed their participant centers into page builder pages.
  • To set a session variable, you can append a query parameter like s_anyparameter=anyvalue to any Luminate Online URL. Luminate Online has a servlet called AjaxHelper which you can call with an AJAX request and append this query parameter, e.g. https://secure3.convio.net/shortname/site/AjaxHelper?s_foo=bar (where secure3.convio.net/shortname is your organization's secure path).


    Alternatively, note that there is an API method called getTagInfo (http://open.convio.com/api/#content_api.gettaginfo_method.html) which evaluates Luminate Online template tags like S- or U-Tags. You can pass a U0 tag to this method and it will set a session variable.
  • But is it possible to initialize a [[U0]] value with JS?

    (now that I think about it, I'm guessing no, because the tags evaluate before the JS runs)
  • Making an AJAX request to a URL like https://secure3.convio.net/shortname/site/AjaxHelper?s_foo=bar will have the same effect as [[U0:foo=bar]], e.g.

    $.ajax({<br /><br/>url: 'AjaxHelper?s_foo=bar'<br /><br/>})


    Alternatively, you can use the getTagInfo API method, like:

    $.ajax({<br /><br/>url: 'CRContentAPI',<br /><br/>type: 'POST',<br /><br/>data: 'v=1.0&api_key=my_key&response_format=json&method=getTagInfo&content=' + encodeURIComponent('[[U0:foo=bar]]')<br /><br/>})

Categories