Quick Start

Adding Cohere to your web app
  1. Visit the Cohere dashboard to retrieve your API key. If you haven't previously connected a session, you should see it in the main screen. Otherwise, you can find it in the settings page.

  2. Add Cohere to your web application via NPM/Yarn or a script tag. Cohere.init should be called on the web browser, not the server.

NPM/Yarn
Script Tag
Segment
Bubble.io
Shopify
Wix
Memberstack
NPM/Yarn

Install the cohere-js package via NPM:

npm install cohere-js # or, yarn add cohere-js

Then, import Cohere and call Cohere.init like so:

import Cohere from "cohere-js";
Cohere.init("INSERT_API_KEY_HERE");
Script Tag

Paste your Cohere snippet into the <head> tag of your site:

<script>!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl"],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();</script>
<script>window.Cohere.init("INSERT_API_KEY_HERE");</script>
Segment

Install the cohere-js package via NPM:

npm install cohere-js # or, yarn add cohere-js

Then, import Cohere and call Cohere.init like so:

import Cohere from "cohere-js";
Cohere.init("INSERT_API_KEY_HERE", { segmentIntegration: true });

All Segment identify calls will be forwarded to Cohere, and your logged in users will be identified in the Cohere dashboard.

Bubble.io

In your Bubble application editor, navigate to Settings in the left sidebar. Under SEO / metatags, find Script/meta tags in header.

Insert the following code snippet, taking care to replace INSERT_API_KEY_HERE with your API key:

<script>!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl"],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();</script>
<script>window.Cohere.init("INSERT_API_KEY_HERE");</script>

For more information, please visit our Bubble.io documentation here.

Shopify

Paste the following code into the <head> tag of your Shopify website's theme.liquid file.

<script>!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl"],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();</script>
<script>window.Cohere.init("INSERT_API_KEY_HERE");</script>

For a more detailed guide, check out our Shopify integration documentation here.

Wix

Wix has a comprehensive guide detailing how to add third-party code to your site. Simply copy the following code snippet and deploy to All pages in the Head, replacing INSERT_API_KEY_HERE with your API key:

<script>!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl"],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();</script>
<script>window.Cohere.init("INSERT_API_KEY_HERE");</script>

For more information, visit our Wix documentation here.

Memberstack

In all pages where you've added the Memberstack script, add the following script tags (taking care to replace INSERT_API_KEY_HERE with your API key):

<script>!function(){var e=window.Cohere=window.Cohere||[];if(e.invoked)console.error("Tried to load Cohere twice");else{e.invoked=!0,e.snippet="0.2",e.methods=["init","identify","stop","showCode","getSessionUrl"],e.methods.forEach(function(o){e[o]=function(){var t=Array.prototype.slice.call(arguments);t.unshift(o),e.push(t)}});var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src="https://static.cohere.so/main.js",o.crossOrigin="anonymous";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t)}}();</script>
<script>window.Cohere.init("INSERT_API_KEY_HERE");</script>
<script>
MemberStack.onReady.then(member => { if (member.loggedIn) { Cohere.identify(member.id, { displayName: [member.fname, member.lname].filter(Boolean).join(" "), email: member.email }); }});
</script>

Cohere should now be working on your site after a refresh, and logged in users will be identified inside the dashboard.

After adding the script, you should see your session in the Cohere dashboard! If you're still having trouble, check out the troubleshooting section.

You can now (optionally) identify your users and exclude sensitive elements.