Collecting Web Analytics

  • To start collecting frontend analytics from your landing page or web app, simply drop in the UserFlux JavaScript SDK.

  • Grab your UserFlux Write-Only API Key from the settings section of the dashboard.

  • The NPM package can be found here: https://www.npmjs.com/package/@userflux/browser-js

NPM Setup
npm i @userflux/browser-js

import UserFlux from '@userflux/browser-js'

UserFlux.initialize('YOUR_WRITE_ONLY_API_KEY', { 
    autoCapture: ['page_views'], 
    allowCookies: true, 
    autoEnrich: true, 
    trackSession: true,
    defaultTrackingProperties: { project: 'Web App' } 
})
Identify A User
import UserFlux from '@userflux/browser-js'

UserFlux.identify({
    properties: { email: 'johndoe@gmail.com', name: 'John' },
    userId: 'USER_ID',
    enrichDeviceData: true,
    enrichLocationData: true
})
Track A Custom Event
import UserFlux from '@userflux/browser-js'

UserFlux.track({
    event: 'purchase',
    properties: { amount: 140.50, paymentMethod: 'Credit Card' },
    userId: 'USER_ID',
    enrichDeviceData: true,
    enrichLocationData: true
})
Setup Without A Package Manager
<head>
    <!-- Your other head tag code -->
    <script type="module" async>
    import UserFlux from 'https://cdn.skypack.dev/@userflux/browser-js'
    UserFlux.initialize('YOUR_WRITE_ONLY_API_KEY', { 
        autoCapture: ['page_views'], 
        allowCookies: true, 
        autoEnrich: true, 
        trackSession: true,
        defaultTrackingProperties: { project: 'Landing Page' } 
    })
    </script>
</head>

Last updated