How to install LiveSession with React or Angular application?

LiveSession provides a SDK package to install script in your favorite framework. This tool also let you work easier with LiveSesion API. We've prepared some examples how to install tracking code in React and Angular.

In both cases start with installing LiveSesion SDK

npm i @livesession/sdk

or

yarn add @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";
  1. 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"));
  2. If you are using something like 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 with useEffect hook

    import ls from "@livesession/sdk";
    
    const Layout = () => {
        useEffect(() => {
            ls.init("YOUR_TRACK_ID");
            ls.newPageView();
        },[])
        return (
            // your layout
        )
    }
    export default Layout;

Angular usage

  1. Import SDK into your main app component

  2. Import OnInit from @angular/core

  3. Implement OnInit and call LiveSession init method in ngOnInit function

    // app.component.ts
    import ls from '@livesession/sdk'
    export class AppComponent implemets OnInit {
        ngOnInit(){
            ls.init("YOUR_TRACK_ID");
            ls.newPageView();
        }
    }

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

Didn’t find an answer?

Try using the search engine or just contact us

[email protected]Chat with us

Start using LiveSession for free now.

Free 14-day trial

No credit card required

Easy setup