forked from optimizely/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension_apply.js
29 lines (25 loc) · 1.03 KB
/
extension_apply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// For full developer documentation see:
// https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin
var utils = optimizely.get('utils');
// Function to initialize Facebook JS SDK
window.fbAsyncInit = function() {
FB.init({
appId : extension.appId,
autoLogAppEvents : true,
xfbml : true,
version : 'v2.12'
});
};
// Async function to load Facebook SDK
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'))
// Optimizely utility function to wait for the Body to appear in the DOM before appending FB Messeenger Widget
// https://developers.optimizely.com/x/solutions/javascript/reference/#function_waitforelement
utils.waitForElement('body').then(function(el){
el.insertAdjacentHTML('afterbegin', extension.$html);
});