Web SDK
Sending messages to your website
The Website SDK
The SDK consists of a javascript file. You are recommended to link to the version on the 2mee CDN. This will allow you you remain up to date without having to check for updates. The SDK itself uses the sweetalert2@11 dialog package to display the popup messages.
After loading the javascript, the SDK is initialised using in the Appear2mee.initWithID function using the Web ID that is generated in the settings section of an App in the 2mee platform.
Installation - Simple Site
For a single page website the full install is shown below. The script is loaded asynchronously to avoid delaying page loaded. SDK commands are then pushed onto a command layer and processed once the script has loaded. The Appear2mee SDK is initialised with a initWithID command which requires an ID to associate the website with the messages that your organisation will post. Optionally you can add a setPosition call to define where on the page a dialog will appear. The default is bottom-right. This code should be place in the <head></head> section of the webpage.
For multiple page sites the same install is required on each page. Of course you should not include the SDK on pages that you do not want the messages to appear.
The appear2mee SDK will report its version number on the console e.g., Appear2mee V2.3.21. By using the appear2meeV2_3.js any bug fixes or improvements that are not breaking changes will be available as this version is updated with any changes. If you want to keep using a particular version then you should use the specific version name, e.g., appear2meeV2_3_21.js.
If you are using the appear2mee only for inlineMessages/eventMessages or sms messages, then you do not need the pulled message feature and it is best to turn this off as it polls messages that you will never use. By default it is on. To turn off the polling you can do on init,
Note the javascript window.Appear2meeLayer = window.Appear2meeLayer || [];
sets up a command queue. Commands are pushed on to this queue using the appear2mee() function. Only when the SDK script is loaded will it start executing these commands.
User ID
When the SDK is first loaded by a user a unique ID is generated and stored in the browser local storage. On subsequent loads if an existing ID is present it will be used. Note that the same user will have different IDs if the user a different browser or incognito mode, or clear their local storage.
It is also possible to set a userID using the SDK. This can be used where the user has logged into a site or where an alternative ID is available.
Message Types
There are a number of message types, but they broadly divide into to categories, pulled messages and capsule based messages.
Pulled Messages
Pull messages are scheduled by the 2mee Exchange. They have a start and end time. The appear2mee SDK polls the 2mee Exchange and stores a reference to any scheduled messages. When the play time of that message arrives it will generate a popup with the message.
Topics
The are two types of exchange scheduled popup messages, global messages and topic messages. Global messages are displayed by the SDK unless specifically requested not to. Topic messages are only displayed if that particularly topic has been requested using the receiveTopic command. A topic is just a string. For example, appear2mee("receiveTopics","homepage") would allow messages for the topic homepage to be received and played. Multiple topics can be set using an array, appear2mee("receiveTopics", ["homepage", "contacts"])
However, rather than specify topics individually it is better to have them defined automatically using, for example, the page name. Note for http://site.com/hierarchy/page/ type page locations a different filter is needed see the WordPress version below.
Topics can also be set on the exchange, and the exchange can also be used to decline topics generated by by the webpage should be set once
The receiveTopics command not only registers the topic to be received by also communicates the topic request to the platform, so that the topic is added to the available topics. An optional Boolean learnQuickly can be added as a second argument to speed up the transmission of topic information to the platform. Without the learnQuickly option as true communication of topics is done lazily (within maybe 30 seconds of loading the page), which maybe too slow for the eager developer.
Some pages or sections of your site might require no messages at all to be displayed, or only topic messages. The receiveOnlyTopics command will allow only topic messages to be displayed, eg., appear2mee("receiveOnlyTopics", "checkout"). To receive no messages at all the appear2mee("receiveOnlyTopics",null) can be used
Dialog Auto Height
By default, the popup dialog sets html's and body's CSS height to auto !important. If this behaviour is not compatible with your project's layout, set the dialogHeightAuto to false using
Dialog Z-Index
By default, the popup dialog has z-index of 10000 (prior to V2_0_10 it was 1060). If this is not compatible with your project's layout, set the z-index using the setSwalZIndex method. This sets the swal2-container of the sweetAlert2 dialog z-index to the required value.
Inline Messages
Normally messages popup and block other activity. Inline messages are effectively a named videos place in an iframe . To use an inline message a Capsule must be used. A Capsule is a named message on the 2mee Platform. It has the advantage that the video can be replaced without changing the name. For example a "welcome" message can be replaced without changing the web site as the inline message displays the contents of the Capsule. An inline message is placed in html using the code below. The Appear2mee SDK must also be include in the <head> section of the page.
This code defines an iframe in which the message will be displayed. The this argument refers to the iframe (it is this iframe) and the last argument is the name of the Capsule defined in the 2mee Platform.
An inline message can also be configured to have a background image, your logo perhaps.
Random Selection of a Message
It is possible to configure inline messages to select a message at random from an array of messages.
When the page is loaded on of these message will be displayed, the choice is random. If the chosen message does not exist then no message is displayed. That is why it is a good idea to set the width="0px" height="0px" frameborder="0" in the iframe, so that there is nothing rendered in the page. If you wish to weight the random selection you can supply weights to the array. In this case each element of the array must have a weight.
The setting above will give on average 11 MessageName and 10 AnotherMessageName for every 21 page loads. Note as this is an average, it will take quite a few samples to detect this weighting.
Inline Message state callbacks
The inlineMessage can be made more interactive using some extra functions and callbacks messages from the player to use these the inline message call has an extra parameter a unique message id that the developer defines. This is used to identify which (if you have more than one) inline message is returning state information.
The state of inline messages can be received by registering a callback function using the appear2mee("setInlineMessageStateFn", callback) method. This will set your callback function to receive state information messages from all the inlineMessages that are active on your page.
The callback function has three arguments, the unique id you assigned to the inline message, the state of that message, at present one of playButtonClick, playReady, playEnd, playStarted, and loading, and a value argument. The value argument is null except in the loading state, where it will give the percentage of the messages current loaded (0.0 -> 100.0).