GithubHelp home page GithubHelp logo

next-intercom's Introduction

next-intercom

next-intercomMaintainabilitycodecov

create intercom chat composer in any browser or on the server using javascript. Keep messager up across SSR pages. Easy drop in for Next.js Extra configuration for priority adjustments to keep the main thread unblocked.

Installation

yarn install next-intercom

How to use

On the client or you can use the script on the server like Next.js using the ssr toggle. If your using Next.js you can simply just add the process.browser for ssr to render intercom SSR and have it loaded initally.

const { loadIntercom, initIntercomWindow } = require("next-intercom");

/* 
  Generate the intercom script and load the composer
*/
loadIntercom({
  appId: "myintercomappid", // default : ''
  email: "[email protected]", //default: ''
  name: "Some Name", //default: RandomName
  ssr: false, // default: false
  initWindow: true, // default: true
  delay: 0, // default: 0  - usefull for mobile devices to prevent blocking the main thread
});

// If init was set to false initiate the window when needed
initIntercomWindow({ appId: "myintercomappid", email: "[email protected]" });

example using on the server

const { createIntercomSSR } = require("next-intercom");

// Optiobal appId property unless app was not established: example in nodejs, make sure to globally set fetch to your request type like axios etc
app.get("/intercom", (req, res) =>
  createIntercomSSR({
    appId: req.query.appId,
  })
);

Or use in a fetch like manner if needed from the server or clientside. This returns the script for intercom inline for usage.

const { createIntercomSSR } = require("next-intercom");

async function fetchIframe() {
  const intercomScript = await createIntercomSSR(appId);
  return intercomScript;
}

Stop intercom and close composer.

const { shutdownIntercom } = require("next-intercom");

shutdownIntercom();

Add events to Intercom.

const { updateIntercom } = require("next-intercom");

updateIntercom("onShow", function newEvent() {
  console.log("composer opened!");
});

Track an Intercom event.

const { trackEvent } = require("next-intercom");

var metadata = {
  invitee_email: "[email protected]",
  invite_code: "ADDAFRIEND",
};

trackEvent("invited-friend", metadata);

About

Simply get started with intercom in your app using javascript.

Methods

The intercom constructor using window.Intercom('method')

  1. boot - load intercom
  2. reattach_activator
  3. update - update intercom composer data

next-intercom's People

Contributors

j-mendez avatar dependabot[bot] avatar botv avatar jackmerrill avatar dovahbrownies avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.