Skip to content

Commit 843e842

Browse files
revert(audience): drop Identify(Dictionary<string, object> traits) overload
Reverts 9b00cce, which added a traits-only Identify overload that mirrored the @imtbl/audience Web SDK's identify(traits) shape. The overload emits identify events with no identityType and cannot carry one meaningfully (no userId to attach one to). CDP requires identityType on every identify event to match records during data deletion, so records produced by this path would be unreachable for erasure. Mechanical prerequisite for SDK-222: making identityType mandatory on MessageBuilder.Identify is a compile error while this overload exists. Web SDK parity will be reopened under a separate ticket once the Web SDK drops its equivalent for the same CDP reason. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1ca0773 commit 843e842

2 files changed

Lines changed: 0 additions & 129 deletions

File tree

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -207,36 +207,6 @@ public static void Identify(string userId, string? identityType, Dictionary<stri
207207
Enqueue(msg);
208208
}
209209

210-
// Attach or update traits for the current anonymous user without
211-
// supplying a user id. Useful when only the anonymous profile is
212-
// known, or when only traits have changed since a prior Identify().
213-
//
214-
// Does not modify the current user id — a subsequent Track() still
215-
// carries whatever id was set by a previous Identify(userId, ...) call.
216-
public static void Identify(Dictionary<string, object> traits)
217-
{
218-
if (!_initialized) return;
219-
220-
if (traits == null)
221-
{
222-
Log.Warn("Identify(traits) called with null traits — dropping.");
223-
return;
224-
}
225-
if (_consent != ConsentLevel.Full)
226-
{
227-
Log.Warn($"Identify discarded — requires Full consent, current is {_consent}");
228-
return;
229-
}
230-
231-
var config = _config;
232-
if (config == null) return;
233-
234-
var anonymousId = Identity.GetOrCreate(config.PersistentDataPath!, _consent);
235-
var msg = MessageBuilder.Identify(anonymousId, userId: null, identityType: null,
236-
config.PackageVersion, SnapshotCallerDict(traits));
237-
Enqueue(msg);
238-
}
239-
240210
// Link two user ids for the same player.
241211
public static void Alias(string fromId, IdentityType fromType, string toId, IdentityType toType) =>
242212
Alias(fromId, fromType.ToLowercaseString(), toId, toType.ToLowercaseString());

src/Packages/Audience/Tests/Runtime/ImmutableAudienceTests.cs

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -397,105 +397,6 @@ public void Identify_AnonymousConsent_IsIgnored()
397397
"identify should be discarded at Anonymous consent");
398398
}
399399

400-
[Test]
401-
public void IdentifyTraits_FullConsent_WritesIdentifyWithTraitsAndNoUserIdField()
402-
{
403-
ImmutableAudience.Init(MakeConfig(ConsentLevel.Full));
404-
405-
ImmutableAudience.Identify(new Dictionary<string, object> { ["plan"] = "pro" });
406-
ImmutableAudience.Shutdown();
407-
408-
var queueDir = AudiencePaths.QueueDir(_testDir);
409-
var contents = Directory.GetFiles(queueDir, "*.json")
410-
.Select(File.ReadAllText).ToList();
411-
var identifyMsg = contents.FirstOrDefault(c => c.Contains("\"identify\""));
412-
Assert.IsNotNull(identifyMsg, "traits-only identify should enqueue an identify event");
413-
Assert.IsTrue(identifyMsg.Contains("\"plan\"") && identifyMsg.Contains("\"pro\""),
414-
"traits payload should be present");
415-
Assert.IsFalse(identifyMsg.Contains("\"userId\""),
416-
"traits-only identify must not attach a userId field");
417-
Assert.IsFalse(identifyMsg.Contains("\"identityType\""),
418-
"traits-only identify must not attach an identityType field");
419-
}
420-
421-
[Test]
422-
public void IdentifyTraits_AnonymousConsent_IsIgnored()
423-
{
424-
ImmutableAudience.Init(MakeConfig(ConsentLevel.Anonymous));
425-
426-
ImmutableAudience.Identify(new Dictionary<string, object> { ["plan"] = "pro" });
427-
ImmutableAudience.Shutdown();
428-
429-
var queueDir = AudiencePaths.QueueDir(_testDir);
430-
var contents = Directory.GetFiles(queueDir, "*.json")
431-
.Select(File.ReadAllText).ToList();
432-
Assert.IsFalse(contents.Any(c => c.Contains("\"identify\"")),
433-
"Identify(traits) should be discarded at Anonymous consent");
434-
}
435-
436-
[Test]
437-
public void IdentifyTraits_NoneConsent_IsIgnored()
438-
{
439-
ImmutableAudience.Init(MakeConfig(ConsentLevel.None));
440-
441-
ImmutableAudience.Identify(new Dictionary<string, object> { ["plan"] = "pro" });
442-
ImmutableAudience.Shutdown();
443-
444-
var queueDir = AudiencePaths.QueueDir(_testDir);
445-
var files = Directory.Exists(queueDir)
446-
? Directory.GetFiles(queueDir, "*.json")
447-
: Array.Empty<string>();
448-
Assert.IsFalse(files.Select(File.ReadAllText).Any(c => c.Contains("\"identify\"")),
449-
"Identify(traits) should be discarded at None consent");
450-
}
451-
452-
[Test]
453-
public void IdentifyTraits_NotInitialised_IsIgnored()
454-
{
455-
Assert.DoesNotThrow(() => ImmutableAudience.Identify(new Dictionary<string, object>()));
456-
}
457-
458-
[Test]
459-
public void IdentifyTraits_NullTraits_DropsAndWarns()
460-
{
461-
ImmutableAudience.Init(MakeConfig(ConsentLevel.Full));
462-
463-
var lines = new List<string>();
464-
Log.Writer = lines.Add;
465-
try
466-
{
467-
Assert.DoesNotThrow(() => ImmutableAudience.Identify((Dictionary<string, object>)null));
468-
Assert.That(lines, Has.Some.Contains("null traits"));
469-
}
470-
finally { Log.Writer = null; }
471-
472-
ImmutableAudience.Shutdown();
473-
var queueDir = AudiencePaths.QueueDir(_testDir);
474-
var contents = Directory.GetFiles(queueDir, "*.json")
475-
.Select(File.ReadAllText).ToList();
476-
Assert.IsFalse(contents.Any(c => c.Contains("\"identify\"")),
477-
"null traits must not produce an identify event");
478-
}
479-
480-
[Test]
481-
public void IdentifyTraits_DoesNotOverwritePriorUserId()
482-
{
483-
ImmutableAudience.Init(MakeConfig(ConsentLevel.Full));
484-
485-
ImmutableAudience.Identify("user-123", IdentityType.Passport);
486-
ImmutableAudience.Identify(new Dictionary<string, object> { ["plan"] = "pro" });
487-
ImmutableAudience.Track("after_traits_identify");
488-
ImmutableAudience.Shutdown();
489-
490-
var queueDir = AudiencePaths.QueueDir(_testDir);
491-
var trackMsg = Directory.GetFiles(queueDir, "*.json")
492-
.Select(File.ReadAllText)
493-
.FirstOrDefault(c => c.Contains("\"after_traits_identify\""));
494-
Assert.IsNotNull(trackMsg, "track event should be enqueued");
495-
Assert.IsTrue(trackMsg.Contains("\"user-123\""),
496-
"Track after traits-only Identify must still carry the prior userId");
497-
}
498-
499400
[Test]
500401
public void Alias_FullConsent_WritesAliasEvent()
501402
{

0 commit comments

Comments
 (0)