Currently we only offer the C# .NET Library for .NET 7 and older. If there are people wanting a version that supports earlier framework support, we will create one. The complete source code is open source and can be found on github.
You can easily install it to any of your projects with nuget.
You can create an instance of SiteSightsTracking
class specifying your websites API Key.
// In a read-world scenario, you would use a cached HttpClient instance or one from a HttpClientFactory
var httpClient = new HttpClient();
var options = new SiteSightsTrackingOptions
{
ApiKey = "YOUR_API_KEY",
};
var iOptions = Microsoft.Extensions.Options.Options.Create(options);
var tracking = new SiteSightsTracking(iOptions, httpClient);
You can also register SiteSightsTracking
for Dependency injection in ASP.NET by adding it as follows.
// Configure the SiteSightsTracking Options and register them to the service collection
// Note: You can also load the options from a configuration file or environment variables via IConfiguration
builder.Services.Configure<SiteSightsTrackingOptions>(options =>
{
options.ApiKey = "YOUR_API_KEY"; // Required: Will be found on your sitesights.io dashboard under websites > edit website, do not share this anywhere in the frontend.
// Optional: options.Url = "https://app.sitesights.de"; // Default value, currently SiteSights only supports this url
});
// Register the SiteSightsTracking service with the specified ServiceLifetime
// Note: You can also use the default ServiceLifetime.Scoped
builder.Services.AddSiteSightsTracking();
After this you can easily get the ISiteSightsTracking by the default dependency injection way of ASP.NET Core.
public class HomeController : Controller {
private readonly ISiteSightsTracking _tracking;
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger, ISiteSightsTracking tracking) {
_logger = logger;
_tracking = tracking;
}
}
The class SiteSightsTracking
offers following method call:
var resp = await tracking.PageView(new SiteSightsPageView() {
Metrics = new ClientMetrics() {
Browser = new BrowserMetric() {
IP = "91.48.119.123",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
},
Identify = new SessionMetric() {
ClientId = null,
},
Language = new LanguageMetric() {
Code = "en",
},
Page = new PageMetric() {
Absolute = "https://app.sitesights.io/analytics",
},
Referrer = new ReferrerMetric() {
Absolute = "https://app.sitesights.io",
},
Screen = new ScreenMetric() {
Height = 200,
Width = 200
},
Location = new LocationMetric() {
ContinentCode = "AF",
CountryCode = "AF",
City = "test",
PostalCode = "33100",
Region = "test",
RegionCode = "te",
Timezone = "timezone",
}
}
});
The class SiteSightsTracking
offers following method call:
var resp = await tracking.Event(new SiteSightsEvent() {
Name = "test",
Parameters = new List<EventParameter>() {
new EventParameter() {
Name = "param1",
Value = "value2"
}
},
Metrics = new ClientMetrics() {
Browser = new BrowserMetric() {
IP = "91.48.119.123",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0",
},
Identify = new SessionMetric() {
ClientId = null,
},
Language = new LanguageMetric() {
Code = "en",
},
Page = new PageMetric() {
Absolute = "https://app.sitesights.io/analytics",
},
Referrer = new ReferrerMetric() {
Absolute = null,
},
Screen = new ScreenMetric() {
Height = 200,
Width = 200
},
Location = new LocationMetric() {
ContinentCode = "AF",
CountryCode = "AF",
City = "test",
PostalCode = "33100",
Region = null,
RegionCode = null,
Timezone = null,
}
}
});