Created
January 5, 2022 11:57
-
-
Save thclark/b30d3d77f835e7a43193f121fbd334dc to your computer and use it in GitHub Desktop.
UserSnap in react or gatsby
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
import React from 'react' | |
import UserSnap from './src/wherever' | |
/* This is how to use with gatsby... this wraps every page component to include UserSnap. | |
* Depending on your setup you may also need do the same in gatsby-browser.js | |
*/ | |
export const wrapPageElement = ({ element }) => { | |
return ( | |
<> | |
<UserSnap /> | |
{element} | |
</> | |
) | |
} |
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
import React from 'react' | |
import { Helmet } from 'react-helmet' | |
// Replace with the API keys from your widget installation page | |
const USERSNAP_GLOBAL_API_KEY = '<YOUR_USERSNAP_GLOBAL_API_KEY>' | |
/* Render this anywhere in your tree (preferably at the top of your app) to invoke the usersnap widget. | |
*/ | |
const UserSnap = () => { | |
return ( | |
<Helmet> | |
<script type="text/javascript"> | |
{` | |
window.onUsersnapCXLoad = function(api) { | |
api.init(); | |
} | |
var script = document.createElement('script'); | |
script.defer = 1; | |
script.src = 'https://widget.usersnap.com/global/load/${USERSNAP_GLOBAL_API_KEY}?onload=onUsersnapCXLoad'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
`} | |
</script> | |
</Helmet> | |
) | |
} | |
export default UserSnap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment