This tutorial will help you start sending analytics data from your ASP.NET app to Segment and any of our integrations, using our .NET and analytics.js library. As soon as you're setup you'll be able to turn on analytics tools, ad conversion pixels, email tools and lots of other integrations with the flip of a switch!
The best analytics installation combines both client-side and server-side tracking. A client-side analytics.js installation allows you to install A/B testing, heat mapping, session recording, and ad optimization tools. A server-side .NET installation allows you to accurately track events that aren't available client-side, such as payments. For best practices, check out our guide client-side vs. server-side.
Step 1: Add Analytics.js to your ASP.NET Master Page
Once you create a project on Segment,
You'll be presented with an analytics.js snippet. You can copy the snippet directly into your ASP.NET Site.master:
That snippet will load Analytics.js onto the page asynchronously, so it won't affect your page load speed. As soon as that snippet is running on your site, you can start turning on any integrations on your Segment integrations page and they will start loading on your site automatically! In fact, if you reload, you can start seeing Page calls in our debugger:
Fun fact: if you only want the most basic Google Analytics setup you can stop reading right now. You're done! Just switch on Google Analytics in our interface.
For a more in depth analytics.js tutorial, check out our quick start.
Lots of analytics and marketing tools want to know more information about your users, and what they're doing on your app. In the next section, we'll install the .NET library and start sending an event every time a new user registers on your site.
Step 2: Install our .NET Library
Your website will use our .NET library to identify and track users. You can use the handy-dandy NuGet to easily install the .NET library in your ASP.NET solution:
Install-Package Analytics
You can also accomplish the same thing in the Manage NuGet Packages menu of Visual Studio:
Nice! Now the .NET library needs to know which Segment project you want to send data to. You can initialize the library with your Segment project's writeKeyin the Global.asax file. Then you can use the Analytics singleton in any controller you want.:
Now you're ready to track your first server-side ASP.NET user event.
Step 3: Track Your First ASP.NET Event
Our example ASP.NET site has a login and a register page. You'll want to identify users and track signups from the server-side because it gives you the most accurate count. Other server-side events like Completed Charge should be tracked server-side as well.
To identify newly registered users, we'll use the identify and track call in the Register.aspx.cs controller.
Congratulations! You can now track any event from the browser and the backend. Hundreds of analytics tools await you. If you register a new user in the site, you'll see the identify and track calls in the debugger:
What's Next?
We just walked through the quickest way to get started with Segment using Analytics.js and the .NET library. You might also want to check out our full Analytics.js reference to see what else is possible, or read about the Tracking API methods to get a sense for the bigger picture.
If you're running an Ecommerce site or app you should also check out our Ecommerce API reference to make sure your products and checkout experience is instrumented properly!
ASP.NET Quckstart
This tutorial will help you start sending analytics data from your ASP.NET app to Segment and any of our integrations, using our .NET and analytics.js library. As soon as you're setup you'll be able to turn on analytics tools, ad conversion pixels, email tools and lots of other integrations with the flip of a switch!
If you want to dive deeper at any point, check out the .NET library reference.
Client-side vs Server-side
The best analytics installation combines both client-side and server-side tracking. A client-side analytics.js installation allows you to install A/B testing, heat mapping, session recording, and ad optimization tools. A server-side .NET installation allows you to accurately track events that aren't available client-side, such as payments. For best practices, check out our guide client-side vs. server-side.
Step 1: Add Analytics.js to your ASP.NET Master Page
Once you create a project on Segment,
You'll be presented with an analytics.js snippet. You can copy the snippet directly into your ASP.NET Site.master:
That snippet will load Analytics.js onto the page asynchronously, so it won't affect your page load speed. As soon as that snippet is running on your site, you can start turning on any integrations on your Segment integrations page and they will start loading on your site automatically! In fact, if you reload, you can start seeing
Page
calls in our debugger:Fun fact: if you only want the most basic Google Analytics setup you can stop reading right now. You're done! Just switch on Google Analytics in our interface.
For a more in depth analytics.js tutorial, check out our quick start.
Lots of analytics and marketing tools want to know more information about your users, and what they're doing on your app. In the next section, we'll install the .NET library and start sending an event every time a new user registers on your site.
Step 2: Install our .NET Library
Your website will use our .NET library to identify and track users. You can use the handy-dandy NuGet to easily install the .NET library in your ASP.NET solution:
You can also accomplish the same thing in the
Manage NuGet Packages
menu of Visual Studio:Nice! Now the .NET library needs to know which Segment project you want to send data to. You can initialize the library with your Segment project's
writeKey
in the Global.asax file. Then you can use theAnalytics
singleton in any controller you want.:Now you're ready to track your first server-side ASP.NET user event.
Step 3: Track Your First ASP.NET Event
Our example ASP.NET site has a login and a register page. You'll want to identify users and track signups from the server-side because it gives you the most accurate count. Other server-side events like
Completed Charge
should be tracked server-side as well.To identify newly registered users, we'll use the
identify
andtrack
call in the Register.aspx.cs controller.Congratulations! You can now track any event from the browser and the backend. Hundreds of analytics tools await you. If you register a new user in the site, you'll see the
identify
andtrack
calls in the debugger:What's Next?
We just walked through the quickest way to get started with Segment using Analytics.js and the .NET library. You might also want to check out our full Analytics.js reference to see what else is possible, or read about the Tracking API methods to get a sense for the bigger picture.
If you're running an Ecommerce site or app you should also check out our Ecommerce API reference to make sure your products and checkout experience is instrumented properly!