Platforms
React
Install our SDK into your project
Import LiveSession SDK
import ls from "@livesession/sdk";
- We recommend 2 ways to integrate SDK with your app:
- 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"));
- You can also use lifecycle method
componentDidMount
in your main Layout component. That means you'll be able to enable script on every page.
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
Import SDK into your main app component
Import
OnInit
from@angular/core
Implement
OnInit
and call LiveSession init method inngOnInit
function
// app.component.tsimport ls from '@livesession/sdk'export class AppComponent implemets OnInit {ngOnInit(){ls.init("YOUR_TRACK_ID");ls.newPageView();}}
Gatsby
LiveSession provides a gatsby plugin to integrate script
Install gatsby-plugin-livesession
Go to
gatsby-config.js
Configure a plugin like in following example:
plugins: [{resolve: `@livesession/gatsby-plugin-livesession`,options: {trackID: YOUR_LIVESESSION_TRACKID, // Required, stringkeystrokes: true || false, // Optional, default to falserootHostname: ".example.com", // Optional},},];
Read more about an options you can provide here
Plugin adds code to your site only in production mode.
Capacitor
In general LiveSession support that technology, but you must be sure that resources on your app are available publicly on the Internet.
If you use local server for some reasons you'll need to pass baseURL
option like the following:
__ls("newPageView", {baseURL: "https://your-site.com"});
For example if you set up your local server with hostname:'frontend', androidScheme:'capacitor-app' and href to css in your app is /static/style.css the following style resource must be available at https://your-site.com/static/style.css assuming you set baseURL to https://you-site.com
Electron
Electron doesn't natively support cookies, so LiveSession JavaScript web tracking code won't work because internally we use client-side cookies. We're currently working on a of the electron-cookies package to support tracking.
In the future we'll switch to another browser storage instead of cookies and Electron should works out of the box.
So, to use LiveSession in Electron apps you should:
Install electron-cookies package
Configure a like in following example:
import ElectronCookies from '@livesession/electron-cookies';// enableElectronCookies.enable({origin: 'https://example.com'}); // or ElectronCookies.enable() for default// disableElectronCookies.disable();
The browser cookies needs to know the current URL, but in Electron files are usually served from local filesystem which is not compatibile with cookies.
Treat origin
as a special key for cookies store within all data is saved.
Read more about a package here