If you’re running a web app and want to see both what users do (analytics) and exactly how they do it (session replays), you’ve probably heard of Segment and LogRocket. This guide is for folks who want to wire up these two tools so you get the best of both worlds: unified event data and actionable user session replays, all in one workflow.
You don’t need to be a data engineer, but you should be comfortable editing some code, working with JavaScript, and have access to your app. I’ll skip the fluffy “why analytics matters” stuff—if you’re here, you already care. Let’s get to work.
Why connect LogRocket and Segment?
- Segment handles data routing: it collects analytics events and routes them to other tools.
- LogRocket records user sessions—think “DVR for your web app”—and can capture custom events too.
When you connect them:
- You can link analytics events (like “Clicked Upgrade Button”) to real user sessions for debugging or product research.
- You avoid sending the same data twice, or worse, getting mismatched user IDs.
- You make it easier for non-developers to explore what happened and why.
But don’t expect magic here: Segment and LogRocket don’t “merge” data automatically. You’re wiring up session links and IDs, not building a data warehouse. Still, it’s a big step up from scattered tools.
Step 1: Prerequisites and setup sanity check
Before you start, check these boxes:
- You have a Segment workspace and write access.
- You’ve got a LogRocket account and a project set up.
- Your web app loads JavaScript you control.
- You know where your analytics.js or Segment SDK is initialized.
If you’re missing any of these, stop here and fix it. Otherwise, you’re good to go.
Step 2: Install LogRocket and Segment in your app
2.1. Install LogRocket
If you haven’t added LogRocket yet:
bash npm install --save logrocket
Then, in your app’s main JS entry point (before other code runs):
js import LogRocket from 'logrocket'; LogRocket.init('your-app-id'); // Replace with your LogRocket app ID
Pro tip: Put LogRocket initialization as early as you can, or you’ll miss early errors.
2.2. Install Segment
If you’re using the classic analytics.js
snippet, paste it into your HTML. If you’re using npm:
bash npm install analytics
Then, initialize it in your code:
js import Analytics from 'analytics'; const analytics = Analytics({ app: 'your-app-name', plugins: [ // add plugins here ] });
Or, if you’re using the Segment CDN snippet, just make sure it loads before your app code.
Don’t double-install. If Segment is already there, don’t add it again.
Step 3: Connect LogRocket to Segment
Segment treats LogRocket as a “destination”—meaning events can be sent from Segment to LogRocket, or LogRocket can enrich events with session data.
Here’s the honest version: For most real-world use cases, what you want is to link Segment user/session data to LogRocket sessions, so you can go from an analytics event to a session replay.
3.1. Add LogRocket as a Destination in Segment
- Go to your Segment dashboard.
- Click Destinations > Add Destination.
- Search for “LogRocket” and add it.
- Enter your LogRocket app ID when prompted.
Segment will now forward events to LogRocket. But you’re not done—without a bit of extra wiring, the data will be basic.
Step 4: Sync user identification between Segment and LogRocket
This is the big one. If your Segment events use identify()
to associate events with a user (they should), LogRocket should know about these users too. Otherwise, you’ll be lost in a sea of anonymous session IDs.
4.1. Mirror Segment’s identify calls in LogRocket
Here’s how you do it:
js analytics.on('identify', (event) => { const { userId, traits } = event;
// Mirror the identification in LogRocket LogRocket.identify(userId, traits); });
- This listens for every Segment
identify()
call and tells LogRocket about the user. - Always call
LogRocket.identify
after LogRocket is initialized.
What traits should you pass?
Pass the important stuff: name, email, plan, role—anything you’ll actually use to filter or search in LogRocket. Don’t dump the whole user object.
Warning: Don’t put highly sensitive data (like passwords or credit cards) in traits. LogRocket will record it.
Step 5: Link Segment events to LogRocket sessions
The real magic is being able to go from a Segment event (like a support ticket or “rage click”) to the actual LogRocket session.
5.1. Attach LogRocket session URLs to your Segment events
You can manually add the LogRocket session URL as a property to your Segment events. Here’s how:
js function getLogRocketSessionURL() { if (LogRocket && LogRocket.getSessionURL) { return LogRocket.getSessionURL(); } return null; }
function trackWithSession(event, properties = {}) { const sessionURL = getLogRocketSessionURL(); analytics.track(event, { ...properties, logrocketSessionURL: sessionURL, }); }
// Example usage: trackWithSession('Clicked Upgrade Button', { plan: 'pro' });
Now, every Segment event you care about (pick the big ones, not every scroll) will have a direct link to the LogRocket session. This is a huge time-saver for support and debugging.
Caveat:
- Sometimes, getSessionURL()
isn’t available immediately after LogRocket initializes. Don’t call it before LogRocket is set up.
Step 6: Test your integration
Don’t trust that things “should just work.” Test with a real user flow:
- Load your app locally or in staging.
- Trigger an
identify()
call (log in or sign up). - Perform a trackable action (button click, page view).
- Go to LogRocket and Segment dashboards—verify that:
- The user appears with the right traits in both.
- The events show up in both tools.
- The Segment event includes the
logrocketSessionURL
and clicking it opens the correct session replay.
Troubleshooting tips
- Missing users in LogRocket? Double-check that
LogRocket.identify()
is being called with the right data. - No session URLs in Segment? Make sure you’re grabbing the session URL after LogRocket is initialized.
- Events not flowing to LogRocket? Segment’s destination settings may be off—or your plan may not support custom destinations.
- Weird data mismatch? Check for timing issues (LogRocket not yet initialized before Segment calls).
What to ignore (and what to watch out for)
- Don’t try to send every click or scroll to both tools. You’ll just drown in noise. Focus on the important stuff: signups, purchases, errors, and “aha” moments.
- Don’t treat this as a data warehouse. LogRocket is for replays and debugging, not analytics crunching.
- Don’t send sensitive info. Mask or exclude anything you wouldn’t want an intern seeing.
- Don’t get fancy with event transforms unless you really need it. Keep it simple until you actually have a use case.
Wrapping up: Keep it simple, iterate often
That’s it. You’ve connected Segment and LogRocket, synced user IDs, and set up session linking. Don’t get lost in the weeds of every possible integration—start simple, make sure your key events are tracked, and tweak as you go. Unified analytics aren’t about having every possible datapoint—they’re about answering real questions faster. If you hit problems, don’t be afraid to rip out what doesn’t work. The best setups are the ones you actually use.