Skip to main content
All CollectionsInstall LiveSession
Install LiveSession with React application
Install LiveSession with React application

Learn how to install LiveSession with React.js

Kamil avatar
Written by Kamil
Updated over a year ago

LiveSession provides an SDK package to install script in your favorite framework. This tool also lets you work more easily with LiveSesion API. We’ve prepared some examples of installing tracking code in React.

Start with installing LiveSesion SDK:

npm i @livesession/sdk

React usage

We recommend two ways to integrate SDK with your app. First of all, import a package into your project:

import ls from "@livesession/sdk";

Init script in file where you’re rendering a whole application:

import ls from "@livesession/sdk"; 

ls.init("YOUR-TRACK-ID");
ls.newPageView();
ReactDOM.render(<App />, document.getElementById("root"));

If you are using something like a Layout component, you can also use lifecycle method componentDidMount in it:

import ls from "@livesession/sdk"; 

class Layout extends Component {
componentDidMount(){
ls.init("YOUR_TRACK_ID");
ls.newPageView();
}
render() {
return ( // your layout );
}
}

export default Layout;

If you have React 16.8 or higher - try useEffect hook:

import ls from "@livesession/sdk"; 

const Layout = () => {
useEffect(() => { ls.init("YOUR_TRACK_ID"); ls.newPageView(); },[])
return ( // your layout )
}

export default Layout;

If you want more information about configuration, go to LiveSesion Developers or read instructions on LiveSesion SDK’s Github page.

Did this answer your question?