Installing Insihts via Node Client

For those who prefer using a server-side solution, you can install Insihts using our Node client.

Follow these steps:

  1. Install the Node Client: You can install the Insihts Node client using either npm or yarn. Run one of the following commands in your project directory:

    Using npm:

    npm install @insihts/node
    

    Using yarn:

    yarn add @insihts/node
    
  2. Set Up the Client (CommonJS): Create a new file or update your existing server-side code to include the following setup. Replace YOUR_WEBSITE_ID with your actual website ID from Insihts.

    const Insihts = require('@insihts/node-client');
    
    const client = new Insihts({
      websiteId: 'YOUR_WEBSITE_ID',
    });
    
    // Example: Track a pageview
    client.trackPageview({
      url: 'https://yourwebsite.com',
      referrer: 'https://referrer.com',
    }).then(response => {
      console.log('Pageview tracked', response);
    }).catch(error => {
      console.error('Error tracking pageview', error);
    });
    
  3. Set Up the Client (ES6 Modules): Alternatively, if you are using ES6 module syntax, you can set up the client as follows. Replace YOUR_WEBSITE_ID with your actual website ID from Insihts.

    import Insihts from '@insihts/node';
    
    Insihts.init({
      websiteId: '31238599-94ad-4bec-a265-f409ab07f075', // Your website ID
    });
    
    Insihts.track({ url: '/home' });
    
  4. Set Up the Client (TypeScript): If you are using TypeScript, you can set up the client similarly to the ES6 module syntax. You may need to define types yourself.

    import Insihts from '@insihts/node';
    
    Insihts.init({
      websiteId: '31238599-94ad-4bec-a265-f409ab07f075', // Your website ID
    });
    
    Insihts.track({ url: '/home' });
    
  5. Use the Client: You can now use the client instance to track various events, such as pageviews and custom events. Refer to the Insihts Node client documentation for more details on the available methods.

  6. Verify Installation: Deploy your updated server-side code and verify that data is being sent to Insihts by checking your dashboard.