Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-masks-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"PostHog": patch
---

Disable the client without logging a project token error when the SDK is explicitly disabled or the project token is missing.
18 changes: 18 additions & 0 deletions src/PostHog/Config/PostHogOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using PostHog.Library;

namespace PostHog;

Expand Down Expand Up @@ -26,6 +27,14 @@ public string? ProjectToken

internal bool HasLegacyProjectApiKey => _projectApiKey is not null;

internal void Normalize()
{
_projectToken = _projectToken.NullIfEmpty();
_projectApiKey = _projectApiKey.NullIfEmpty();
PersonalApiKey = PersonalApiKey.NullIfEmpty();
HostUrl = HostUrl.NormalizeHostUrl();
}

/// <summary>
/// Obsolete alias for <see cref="ProjectToken"/>.
/// </summary>
Expand All @@ -49,6 +58,15 @@ public string? ProjectApiKey
/// </remarks>
public string? PersonalApiKey { get; set; }

/// <summary>
/// Whether this client is disabled and should no-op instead of sending data to PostHog. (Default: false)
/// </summary>
/// <remarks>
/// Read once during <see cref="PostHogClient"/> construction. Mutating this after the client is
/// activated has no effect. Re-create the client to change the disabled state.
/// </remarks>
public bool Disabled { get; set; }
Comment thread
marandaneto marked this conversation as resolved.

/// <summary>
/// PostHog API host, usually 'https://us.i.posthog.com' (default) or 'https://eu.i.posthog.com'
/// </summary>
Expand Down
Loading
Loading