Created
April 28, 2021 18:04
-
-
Save albertpak/dff14385102fe76513b9d7bfc9b03412 to your computer and use it in GitHub Desktop.
Add FB Chat messenger to NextJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In case anyone else needs this, here's what I done to add FB Messenger code to my NextJS app - As mentioned before, you need to drop the plugin code into `_document.js` and modify `script` tag | |
import Document, { Html, Head, Main, NextScript } from 'next/document'; | |
export default class MyDocument extends Document { | |
render() { | |
return ( | |
<Html> | |
<Head> | |
{/* code that you want to add to the header */} | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
<div id="fb-root"></div> | |
<script | |
dangerouslySetInnerHTML={{ | |
__html: ` | |
window.fbAsyncInit = function() { | |
FB.init({ | |
xfbml : true, | |
version : 'v10.0' | |
}); | |
}; | |
(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')); | |
`, | |
}} | |
/> | |
<div className="fb-customerchat" | |
attribution="page_inbox" | |
page_id="YOUR_FB_PAGE_ID"> | |
</div> | |
</Html> | |
) | |
} | |
} |
not working
fails
can not
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, and I have an question, why did you add script out of body tag ?