Migrating to RudderStack from Segment in 3 steps

Customer event data has become an essential asset for many organizations as they look to build out their data stack and make that tightly integrated with their marketing, product and sales functions. For a long time, Segment was a leader in ingesting event data and integrating it with various SaaS tools, but they haven’t kept up with modern data stack architectures that emphasize data ownership and features built for technical users.

RudderStack is an open-source alternative to Segment with a warehouse-first model that ingests, processes and delivers data without storing it, eliminating unnecessary data silos and security risks. (Feel free to checkout this page for a more detailed explanation on how RudderStack differentiates itself from Segment.)

If you’re ready to make the switch, we’ve got great news: we’re API compatible with Segment, which makes migrating your event instrumentation easy. .

In this guide, we’ll walk through 3 simple steps that will help you migrate your SDK sources from Segment to RudderStack with minimal time and effort.

Step 1: Install the RudderStack SDK and Prepare Existing Event Instrumentation

Step 2: Map your destinations, test (test, test) and flip the switch! 

Step 3: Explore additional features to add to your developer toolset


If you are more of a visual learner, check out this video that walks through the steps required for this migration.

Step 1: Install the RudderStack SDK and Prepare Existing Event Instrumentation

As a Segment user, you are already familiar with the process of installing SDKs. In this guide, we’ll use the Javascript SDK as our example, but the same steps apply for other SDKs (RudderStack has 16 SDKs that cover web, mobile, server-side and gaming).

RudderStack’s SDKs are API compatible with Segment’s, meaning you can use all of your existing event instrumentation. Yes, your developers will love you and you’ll save a huge amount of time, but more importantly, you won’t have any interruption in your event data flow through the migration process.


1. As a first step, you’ll need to create an SDK source in RudderStack. If you don’t have an account yet you can sign up for free here.

Click on “+ ADD SOURCE” from the connections view or sources tab and select the JavaScript source. Name the source and then copy the code snippet from the setup tab.

2. Next, locate the snippet that initializes the Segment JavaScript SDK in your code base.   t will look something like this:

JAVASCRIPT
<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="KqkwgiBD43pNT7jHJAt5qE5BVuydomUB";;analytics.SNIPPET_VERSION="4.15.3";
analytics.load("KqkwgiBD43pNT7jHJAt5qE5BVuydomUB");
analytics.page();
}}();
</script>

Replace the above initialization code with the code snippet you copied from the setup tab in the source page if you are looking to fully reset the anonymous ID captured by Segment, or have the SDKs run side by side to carry those anonymous IDs over to RudderStack (see step 5).


3. Now that the SDK is installed, we need to prepare the existing event instrumentation that was implemented for Segment. Because we are API compatible, this step is a quick find & replace in our code Search for the various methods you’ve instrumented (track, identify, etc.), then replace “analytics” with “rudderanalytics. For example, you would search for “analytics.track” and replace it with “rudderanalytics.track”.

Here’s a Segment track call:

JAVASCRIPT
analytics.track("button_clicked",
{
service: "Workshops",
category:"Home"
});

After finding and replacing, it  look like this:

JAVASCRIPT
rudderanalytics.track("button_clicked",
{
service: "Workshops",
category:"Home"
});

Because RudderStack is API compatible with Segment, you don’t have to update any of the actual instrumentation.

Note: it is important to work with your developers to ensure you understand any differences between the development environment where they are making these changes and the production environment where they will be deployed. RudderStack will process the events exactly like Segment, but differences in your codebase between dev and prod can cause discrepancies.


4. Verify that your events are streaming successfully by checking the Live events viewer in the RudderStack source page. Just like Segment, RudderStack will automatically capture site metadata, custom and contextual fields, but note that RudderStack also captures session information to make sessionization, user journeys and attribution models much easier to build and understand downstream.

Optional: migrate your Segment anonymous IDs


5. One aspect of the API compatibility is that you can use the same anonymous IDs previously captured by Segment. This is important because you want to maintain events’ association to their anonymous users so they can be easily mapped to the right user ID once the user is identified. Our customers who need to migrate anonymous IDs generally specify a crossover timeline that captures a critical mass of anonymous traffic.

We have great news for you: RudderStack’s SDKs can handle the migration automatically.

As mentioned above, you can keep the Segment SDK installed and run both SDKs during the crossover period.


In order to configure the RudderStack SDK to use the same anonymous IDs as Segment’s, make sure to add this part at the end of the rudderstackanalytics.load() call from Step 1 so that it looks like this:

JAVASCRIPT
rudderanalytics.load(WRITE KEY,DATA PLANE URL, {
anonymousIdOptions: {
autoCapture: {
enabled: true,
source: "segment"
}
}
});

From a code perspective, this is really all you need to make the switch. Best practice, of course, is to thoroughly test everything in your development environment so you can handle any changes that have happened in the app or website itself, but from an event and SDK perspective, you’re good to go.

Note: RudderStack SDKs are less susceptible to ad blockers than Segments! Check out this guide on how to use the Javascript SDK to detect ad-blocked pages.

Step 2: Map your destinations, test (test, test) and flip the switch!

While we always recommend thorough testing with sample payloads, the initial migration of destination integrations is as easy as setting them up in RudderStack. Note that we support most of the cloud destinations that Segment supports, but have a much deeper library of data warehouses, data lakes and data infrastructure destinations.

  • Data warehouse destinations: RudderStack supports many data warehouse destinations such as Snowflake, Red Shift, BigQuery as well as others within this list. For a detailed walkthrough on how to set it up, check out this guide on how to configure a Data warehouse destination from your Javascript SDK source.

RudderStack writes to the same schema(s) as Segment, it will leverage the existing schemas you’ve already created as warehouse destinations. This means you can move your warehouse destinations over to RudderStack with no interruption in warehouse loads and all your historical data will be maintained. We will structure tables, columns and data types in the exact same way that Segment does.

  • Cloud destinations: We support sending data to an ever growing list of downstream SaaS destinations and webhooks. You can find a full list of the ones currently available here. We’ve also made a lot of updates to support destinations in both device mode and cloud mode with more advanced functionality than that of Segments.

As a best practice here, you’ll want to make sure you involve teams that manage the downstream destinations for them to verify that data is flowing to their tools as expected. If any discrepancies or additional schema mappings need to be made, you can easily use Transformations to make destination specific changes, then use the Live Events viewer or a webhook testing site like webhook.site for additional testing and verification.


Note: Our transformer code for each destination is open-source and can be viewed in our Github repository.

Step 3: Explore additional features to add to your developer toolset

Now that you are fully migrated, you can start exploring features that were built with developer needs in mind:

  • Transformations Segment supports light re-mapping in Protocols and building custom integrations through Functions, but RudderStack’s Transformations let you transform your data in flight (in real-time) before it reaches its destination. Transformations can be written in JavaScript (and soon in Python) and allow you to customize your event data to fit your specific use cases. This includes filtering out both server-side and client-side events (coming soon), removing PII data and enriching events.

Transformations are supported within both a UI and API that makes it easy to build, test and debug before applying any logic to live event data. Check out our open source sample Transformation library for an idea of what’s possible .

  • Data Governance API and Tracking plans: because data quality is top of mind for developers and data engineers alike, we support a Data governance API that can be used to audit event statistics and metadata. This helps capture duplicates or inconsistencies in our ingested event data then pulling them into a set of specs that can be enforced with Tracking plans, check out this guide for an idea on how to get started.

  • ETL and Reverse ETL: as a warehouse-first solution that provides various means to get data into the warehouse using Event streams and ETL, we’ll also help you get that data out of the warehouse with Reverse ETL capabilities, you can then build audiences using Models and our new Audiences tool (coming soon) and activate that data where it will be most valuable within your downstream sales, marketing and analytics tools.

Hopefully at this point we’ve convinced you that flipping the switch from Segment to RudderStack is a simple process. Thank you for reading! Feel free to reach out and continue the conversation in our community Slack if you have any questions or feedback.