PushRadar and .NET

The latest version of PushRadar's API is v2, released July 5, 2019.

Welcome to PushRadar's API documentation for .NET. This article covers calling the various methods of the PushRadar object to publish notifications to a channel in realtime.


PushRadar's .NET library supports .NET Standard 2+.

You will need to install the latest version of the PushRadar NuGet package in order to use the library.

(server)"Hello World!" example

The following example, written in C#, demonstrates broadcasting a "Hello World!" message on a channel called test-channel. Replace your-secret-key with your actual PushRadar secret, which may be obtained from the API page of your dashboard.

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.AddDataItem("message", "Hello World!").Broadcast("test-channel");
(client)Receiving notifications

To find out how to receive notifications by subscribing to channels, check out the documentation for our JavaScript client library.

(tip)Adding multiple data items

For convenience, PushRadar's .NET library supports a fluent syntax to structure broadcasts. To add multiple data items, you can do either of the following:

  • .NET
// ... var radar = new PushRadar.PushRadar(...);
radar.AddDataItem("message", "Hello World!").AddDataItem("item-2", "It's me!")

// --- or ---

    new KeyValuePair<string, object>("message", "Hello World!"),
    new KeyValuePair<string, object>("item-2", "It's me!")
(feature)Action targeting

The following example demonstrates sending a notification to users who have taken a specific action, in this case, users who have purchased item #11.

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.TargetAction("purchased-item-#11").AddDataItem("message", "You have purchased item 11.")

If you include more than one action by calling TargetAction() again or TargetActions(), PushRadar will send the notification to users who have taken any of the given actions.

With the PushRadar JavaScript client library, you can track actions that users have taken using the action method:

  • JavaScript
// ... var radar = new PushRadar(...)
Reverse action targeting

To send a notification to those who have not taken a certain action, you can use the TargetNotAction and TargetNotActions methods. If you specify more than one action identifier, PushRadar will only send the notification to clients who have not taken any of the given actions.

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
    .AddDataItem("message", "You have not purchased item 12.")
(feature)User targeting

User targeting allows you to broadcast notifications to specific users, identified by their user ID. For this example, we will send a new message to the user with ID usr100 in our system by calling TargetUser(). Similarly, to target multiple users, you can call TargetUsers().

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.TargetUser("usr100").AddDataItem("message", "Hey there, from Sam!")
    .AddDataItem("sender_name", "Sam").Broadcast("new-messages");

Make sure to set user IDs on each website page load using the PushRadar JavaScript client library:

  • JavaScript
// Set user ID on initialization
var radar = new PushRadar("your-api-key", "usr100");

// ... or ... radar.setUserID("usr100");

radar.subscribe.to("new-messages", function(notification) {
    alert("New message from " + notification.sender_name); // "New message from Sam"

Note:   If you are targeting users, you should in most cases also use private channels to make for a more secure solution.

(feature)Browser targeting

You can target notifications to users who are currently using specific web browsers by calling TargetBrowser() or TargetBrowsers(), passing in values from the PushRadar.PushRadarBrowsers enumeration. In the following example, we broadcast a notification to users currently using Firefox, Chrome or Internet Explorer:

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
).AddDataItem("data", "This notification is browser-targeted.").Broadcast("test-channel");
(feature)Geo-targeting (ISO 3166-1 alpha-2 )

You can easily broadcast notifications to clients located in certain countries by calling TargetCountry() or TargetCountries(), passing in two-letter ISO country codes. In this example, we broadcast a notification to clients who are currently located in the UK or France:

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.TargetCountries("GB", "FR").AddDataItem("data", "You are in the UK or France!")

Continent targeting is also supported, with specific Target... methods you can call. Below, we add to the previous example and broadcast to all users located in North America, the UK or France:

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.TargetNorthAmerica().TargetCountries("GB", "FR")
    .AddDataItem("data", "You are in North America, the UK or France!")

Each continent has its own dedicated "Target" method:

   - TargetEurope()
   - TargetNorthAmerica()
   - TargetSouthAmerica()
   - TargetOceania()
   - TargetAsia()
   - TargetAfrica()
   - TargetAntarctica()

(feature)IP address targeting

PushRadar supports IP address targeting. When using IP targeting, only clients with the given IP address(es) specified will receive your notification. Below is an example targeting a client with IP address The TargetIP and TargetIPs methods accept both IPv4 and IPv6 addresses.

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");
radar.TargetIP("").AddDataItem("data", "This notification is IP-targeted.")
(secure channels)Channel authentication

Channel authentication is used for private and presence channels. Your authentication endpoint should return a response containing an authentication token if the user can join the channel.

PushRadar provides a ChannelAuth method that generates channel authentication tokens. Here's an example:

  • .NET
var radar = new PushRadar.PushRadar("your-secret-key");

// Get request query parameter "channel" and determine whether the user can join it

// ... if they can, return the auth token
return JsonConvert.SerializeObject(new Dictionary<string, string>() {
    { "authToken", radar.ChannelAuth("channel-name") }

Then register your authentication endpoint URL using the JavaScript client library.

  • JavaScript
var radar = new PushRadar("your-api-key");