Skip to content

Commit 6b2f737

Browse files
committed
remove duplicate method
1 parent 9893398 commit 6b2f737

File tree

2 files changed

+11
-61
lines changed

2 files changed

+11
-61
lines changed

src/PostHog/IPostHogClient.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,15 @@ Task<ApiResult> GroupIdentifyAsync(
7676
/// <param name="properties">Optional: The properties to send along with the event.</param>
7777
/// <param name="groups">Optional: Context of what groups are related to this event, example: { ["company"] = "id:5" }. Can be used to analyze companies instead of users.</param>
7878
/// <param name="sendFeatureFlags">Default: <c>false</c>. If <c>true</c>, feature flags are sent with the captured event.</param>
79-
/// <returns><c>true</c> if the event was successfully enqueued. Otherwise <c>false</c>.</returns>
80-
bool Capture(
81-
string distinctId,
82-
string eventName,
83-
Dictionary<string, object>? properties,
84-
GroupCollection? groups,
85-
bool sendFeatureFlags);
86-
87-
/// <summary>
88-
/// Captures an event with a custom timestamp.
89-
/// </summary>
90-
/// <param name="distinctId">The identifier you use for the user.</param>
91-
/// <param name="eventName">Human friendly name of the event. Recommended format [object] [verb] such as "Project created" or "User signed up".</param>
92-
/// <param name="properties">Optional: The properties to send along with the event.</param>
93-
/// <param name="groups">Optional: Context of what groups are related to this event, example: { ["company"] = "id:5" }. Can be used to analyze companies instead of users.</param>
94-
/// <param name="sendFeatureFlags">Default: <c>false</c>. If <c>true</c>, feature flags are sent with the captured event.</param>
95-
/// <param name="timestamp">The timestamp when the event occurred.</param>
79+
/// <param name="timestamp">Optional: Custom timestamp when the event occurred. If not provided, uses current time.</param>
9680
/// <returns><c>true</c> if the event was successfully enqueued. Otherwise <c>false</c>.</returns>
9781
bool Capture(
9882
string distinctId,
9983
string eventName,
10084
Dictionary<string, object>? properties,
10185
GroupCollection? groups,
10286
bool sendFeatureFlags,
103-
DateTimeOffset timestamp);
87+
DateTimeOffset? timestamp = null);
10488

10589
/// <summary>
10690
/// Determines whether a feature is enabled for the specified user.

src/PostHog/PostHogClient.cs

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,20 @@ public bool Capture(
129129
string eventName,
130130
Dictionary<string, object>? properties,
131131
GroupCollection? groups,
132-
bool sendFeatureFlags)
132+
bool sendFeatureFlags,
133+
DateTimeOffset? timestamp = null)
133134
{
135+
// If custom timestamp provided, add it to properties
136+
if (timestamp.HasValue)
137+
{
138+
properties = AddTimestampToProperties(properties, timestamp.Value);
139+
}
140+
134141
var capturedEvent = new CapturedEvent(
135142
eventName,
136143
distinctId,
137144
properties,
138-
timestamp: _timeProvider.GetUtcNow());
145+
timestamp: timestamp ?? _timeProvider.GetUtcNow());
139146

140147
if (groups is { Count: > 0 })
141148
{
@@ -576,48 +583,7 @@ public async ValueTask DisposeAsync()
576583
_featureFlagsLoader.Dispose();
577584
}
578585

579-
/// <inheritdoc/>
580-
public bool Capture(
581-
string distinctId,
582-
string eventName,
583-
Dictionary<string, object>? properties,
584-
GroupCollection? groups,
585-
bool sendFeatureFlags,
586-
DateTimeOffset timestamp)
587-
{
588-
// Add timestamp to properties as well
589-
properties = AddTimestampToProperties(properties, timestamp);
590-
591-
var capturedEvent = new CapturedEvent(
592-
eventName,
593-
distinctId,
594-
properties,
595-
timestamp: timestamp);
596586

597-
if (groups is { Count: > 0 })
598-
{
599-
capturedEvent.Properties["$groups"] = groups.ToDictionary(g => g.GroupType, g => g.GroupKey);
600-
}
601-
602-
capturedEvent.Properties.Merge(_options.Value.SuperProperties);
603-
604-
var batchItem = new BatchItem<CapturedEvent, CapturedEventBatchContext>(BatchTask);
605-
606-
if (_asyncBatchHandler.Enqueue(batchItem))
607-
{
608-
_logger.LogTraceCaptureCalled(eventName, capturedEvent.Properties.Count, _asyncBatchHandler.Count);
609-
return true;
610-
}
611-
_logger.LogWarnCaptureFailed(eventName, capturedEvent.Properties.Count, _asyncBatchHandler.Count);
612-
return false;
613-
614-
Task<CapturedEvent> BatchTask(CapturedEventBatchContext context) =>
615-
sendFeatureFlags
616-
? AddFreshFeatureFlagDataAsync(context.FeatureFlagCache, distinctId, groups, capturedEvent)
617-
: _featureFlagsLoader.IsLoaded && eventName != "$feature_flag_called"
618-
? AddLocalFeatureFlagDataAsync(distinctId, groups, capturedEvent)
619-
: Task.FromResult(capturedEvent);
620-
}
621587

622588
static Dictionary<string, object>? AddTimestampToProperties(Dictionary<string, object>? properties, DateTimeOffset timestamp)
623589
{

0 commit comments

Comments
 (0)