diff --git a/packages/audience/sdk-sample-app/README.md b/packages/audience/sdk-sample-app/README.md index 176895533d..e4c0fd79c7 100644 --- a/packages/audience/sdk-sample-app/README.md +++ b/packages/audience/sdk-sample-app/README.md @@ -45,7 +45,7 @@ For dev-environment access, leave the key as a test key and set SDK auto-derives sandbox vs prod from the key prefix; dev is not a first-class environment and must be reached via explicit override. -## Ten-step walkthrough +## Nine-step walkthrough 1. Paste a test key into **Setup**, leave Initial Consent at `none`, click **Init**. 2. Open the **Consent** panel, click **anonymous**. Status bar updates. @@ -53,10 +53,9 @@ first-class environment and must be reached via explicit override. 4. Expand **Typed Events → purchase** (6th row in the accordion), fill in `currency=USD`, `value=9.99`, click **Send**. Watch the live TS snippet mirror the form as you type. 5. Set Consent to **full**. 6. In **Identity → Named identify**, enter `user@example.com`, type `email`, traits `{"name":"Jane"}`, click. -7. In **Identity → Traits-only identify**, enter `{"plan":"pro"}`, click. -8. In **Identity → Alias**, connect a Steam ID to the email above. -9. Set Consent back to **none**. Notice the queue purge in the event log. -10. In **Lifecycle → Simulate error**, pick `NETWORK_ERROR` from the dropdown and click **Fire onError**. The `onError` entry lands in the event log with the documented shape. +7. In **Identity → Alias**, connect a Steam ID to the email above. +8. Set Consent back to **none**. Notice the queue purge in the event log. +9. In **Lifecycle → Simulate error**, pick `NETWORK_ERROR` from the dropdown and click **Fire onError**. The `onError` entry lands in the event log with the documented shape. ## `AudienceEvents` catalogue diff --git a/packages/audience/sdk-sample-app/index.html b/packages/audience/sdk-sample-app/index.html index 73359ccf49..cd325bedcd 100644 --- a/packages/audience/sdk-sample-app/index.html +++ b/packages/audience/sdk-sample-app/index.html @@ -209,25 +209,6 @@

-
- - Update traits - -
-

Update an existing player's traits without re-identifying.

-
- - -
-
- -
-
-
-
Alias diff --git a/packages/audience/sdk-sample-app/sample-app.js b/packages/audience/sdk-sample-app/sample-app.js index 0d36c0731d..1a4a93a045 100644 --- a/packages/audience/sdk-sample-app/sample-app.js +++ b/packages/audience/sdk-sample-app/sample-app.js @@ -346,7 +346,7 @@ 'btn-page', 'btn-flush', 'btn-reset', 'btn-shutdown', 'btn-consent-none', 'btn-consent-anon', 'btn-consent-full', 'btn-custom-event', - 'btn-identify', 'btn-identify-traits', + 'btn-identify', ]; function setInitState(on) { @@ -559,7 +559,6 @@ $('btn-consent-anon').addEventListener('click', function () { onSetConsent('anonymous'); }); $('btn-consent-full').addEventListener('click', function () { onSetConsent('full'); }); $('btn-identify').addEventListener('click', onIdentify); - $('btn-identify-traits').addEventListener('click', onIdentifyTraits); $('btn-alias').addEventListener('click', onAlias); ['alias-from-id', 'alias-to-id', 'alias-from-type', 'alias-to-type'].forEach(function (id) { $(id).addEventListener('input', syncAliasButton); @@ -822,27 +821,6 @@ } } - function onIdentifyTraits() { - if (!audience) return; - if (!requiresFullConsent('identify()')) return; - var traits; - try { traits = parseTraits($('traits-json').value); } - catch (err) { log('identify()', 'invalid JSON: ' + err.message, 'err'); return; } - if (!traits) { - log('identify()', 'traits required', 'err'); - return; - } - try { - audience.identify(traits); - enqueued(); - identityMirror.traits = traits; - renderIdentityState(); - log('identify(traits)', traits, 'ok'); - } catch (err) { - log('identify(traits)', errMsg(err), 'err'); - } - } - function onAlias() { if (!audience) return; if (!requiresFullConsent('alias()')) return; diff --git a/packages/audience/sdk/src/sdk.test.ts b/packages/audience/sdk/src/sdk.test.ts index a36ac07a20..6b2129bb58 100644 --- a/packages/audience/sdk/src/sdk.test.ts +++ b/packages/audience/sdk/src/sdk.test.ts @@ -628,53 +628,6 @@ describe('Audience', () => { expect(ids).toHaveLength(0); sdk.shutdown(); }); - - it('ignores null passed as traits', async () => { - const sdk = createSDK({ consent: 'full' }); - - sdk.identify(null as any); - await sdk.flush(); - - const ids = sentMessages().filter((m: any) => m.type === 'identify'); - // null is not a valid traits object — should not enqueue - expect(ids).toHaveLength(0); - - sdk.shutdown(); - }); - - it('ignores array passed as traits', async () => { - const sdk = createSDK({ consent: 'full' }); - - sdk.identify(['not', 'traits'] as any); - await sdk.flush(); - - const ids = sentMessages().filter((m: any) => m.type === 'identify'); - expect(ids).toHaveLength(0); - - sdk.shutdown(); - }); - - it('sends anonymous identify with traits only', async () => { - const sdk = createSDK({ consent: 'full' }); - - sdk.identify({ - source: 'steam', - steamId: TEST_STEAM.id, - }); - await sdk.flush(); - - const msg = sentMessages().find( - (m: any) => m.type === 'identify', - ); - expect(msg).toBeDefined(); - expect(msg.userId).toBeUndefined(); - expect(msg.traits).toEqual({ - source: 'steam', - steamId: TEST_STEAM.id, - }); - - sdk.shutdown(); - }); }); describe('alias', () => { diff --git a/packages/audience/sdk/src/sdk.ts b/packages/audience/sdk/src/sdk.ts index 42837610b0..bb6b031dbb 100644 --- a/packages/audience/sdk/src/sdk.ts +++ b/packages/audience/sdk/src/sdk.ts @@ -285,43 +285,23 @@ export class Audience { * an account. Before identify(), the SDK only knows an anonymous cookie ID. * After, all future events are tied to this player. * - * Named: `sdk.identify('user@example.com', 'email', { name: 'Jane' })` - * Traits only: `sdk.identify({ source: 'steam', steamId: '765...' })` + * `sdk.identify('user@example.com', 'email', { name: 'Jane' })` * * Requires 'full' consent. */ - identify(id: string, identityType: IdentityType, traits?: UserTraits): void; - - identify(traits: UserTraits): void; - - identify( - idOrTraits: string | UserTraits, - identityType?: IdentityType, - traits?: UserTraits, - ): void { + identify(id: string, identityType: IdentityType, traits?: UserTraits): void { if (!canIdentify(this.consent.level)) { this.debug.logWarning('identify() requires full consent — call ignored.'); return; } getOrCreateSession(this.cookieDomain); - if (idOrTraits !== null && typeof idOrTraits === 'object' && !Array.isArray(idOrTraits)) { - this.enqueue('identify', { - ...this.baseMessage(), - type: 'identify', - traits: idOrTraits, - }); - return; - } - - if (typeof idOrTraits !== 'string') return; - - const id = truncate(idOrTraits); - this.userId = id; + const resolvedId = truncate(id); + this.userId = resolvedId; this.enqueue('identify', { ...this.baseMessage(), type: 'identify', - userId: id, + userId: resolvedId, identityType, traits, });