Skip to content

Commit 2c2cfc9

Browse files
fix(audience-sdk-sample-app): adapt to flattened CDN global surface
The sample app and both READMEs were written against the nested ImmutableAudience.Audience.init(...) shape that the CDN bundle originally exposed. #2853 has since flattened the global to ImmutableAudience.init(...) and removed the Audience class from the CDN surface entirely — so the sample app's destructure (\`var Audience = window.ImmutableAudience.Audience\`) now resolves to undefined and every init call throws. - sample-app.js: destructure \`init\` directly into a local \`audienceInit\` var and update all six call sites. - sdk-sample-app/README.md: update the one remaining code snippet that showed Audience.init(...). - sdk/README.md: update the tagline, rewrite the CDN quickstart to destructure \`init\` instead of \`Audience\`, and rephrase the "symbols attached to the global" paragraph to match the new surface (the CDN no longer exposes the Audience class itself).
1 parent b090d86 commit 2c2cfc9

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

packages/audience/sdk-sample-app/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ avoids a misleading "ok" log entry for a call that did nothing.
141141
`'CONSENT_SYNC_FAILED'`, `'NETWORK_ERROR'`, `'VALIDATION_REJECTED'`.
142142
Handle them in an `onError` callback passed at init time:
143143

144-
```ts
145-
audience = Audience.init({
144+
```js
145+
const audience = window.ImmutableAudience.init({
146146
publishableKey: 'pk_imapik-test-...',
147147
onError: (err) => {
148148
switch (err.code) {

packages/audience/sdk-sample-app/sample-app.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
return;
1313
}
1414

15-
var Audience = window.ImmutableAudience.Audience;
15+
var audienceInit = window.ImmutableAudience.init;
1616
var AudienceError = window.ImmutableAudience.AudienceError;
1717
var IdentityType = window.ImmutableAudience.IdentityType;
1818
var SdkAudienceEvents = window.ImmutableAudience.AudienceEvents;
@@ -335,7 +335,7 @@
335335
return;
336336
}
337337
try {
338-
audience = Audience.init(config);
338+
audience = audienceInit(config);
339339
setInitState(true);
340340
currentConsent = config.consent;
341341
log('INIT', {
@@ -742,7 +742,7 @@
742742

743743
function onInitEmptyKey() {
744744
try {
745-
Audience.init({ publishableKey: '' });
745+
audienceInit({ publishableKey: '' });
746746
log('Init with empty key', 'unexpected: init did not throw', 'err');
747747
} catch (err) {
748748
log('Init with empty key', {
@@ -768,7 +768,7 @@
768768
currentUserId = null;
769769
currentAnonId = null;
770770
try {
771-
audience = Audience.init(readConfig());
771+
audience = audienceInit(readConfig());
772772
currentConsent = $('initial-consent').value;
773773
setInitState(true);
774774
updateStatus();
@@ -790,7 +790,7 @@
790790
currentUserId = null;
791791
currentAnonId = null;
792792
try {
793-
audience = Audience.init(withLiveConfig({
793+
audience = audienceInit(withLiveConfig({
794794
baseUrl: DEAD_BASE_URL,
795795
consent: 'anonymous',
796796
}));
@@ -819,7 +819,7 @@
819819
currentUserId = null;
820820
currentAnonId = null;
821821
try {
822-
audience = Audience.init(withLiveConfig({
822+
audience = audienceInit(withLiveConfig({
823823
publishableKey: 'pk_imapik-test-revoked-0000000000000000',
824824
consent: 'anonymous',
825825
}));
@@ -848,7 +848,7 @@
848848
currentUserId = null;
849849
currentAnonId = null;
850850
try {
851-
audience = Audience.init(withLiveConfig({
851+
audience = audienceInit(withLiveConfig({
852852
baseUrl: DEAD_BASE_URL,
853853
consent: 'none',
854854
}));

packages/audience/sdk/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ yarn add @imtbl/audience
4040
```
4141

4242
For the CDN build, drop one `<script>` tag into your HTML and call
43-
`ImmutableAudience.Audience.init({...})` — no bundler, no `npm install`.
43+
`ImmutableAudience.init({...})` — no bundler, no `npm install`.
4444
Once `@imtbl/audience` is published, the bundle URL will be
4545
`https://cdn.jsdelivr.net/npm/@imtbl/audience@<version>/dist/cdn/imtbl-audience.global.js`
4646
(replace `<version>` with a specific release tag).
@@ -71,10 +71,10 @@ audience.shutdown();
7171
<script src="https://cdn.jsdelivr.net/npm/@imtbl/audience@<version>/dist/cdn/imtbl-audience.global.js"></script>
7272
<script>
7373
const {
74-
Audience, AudienceError, AudienceEvents,
74+
init, AudienceError, AudienceEvents,
7575
IdentityType, canTrack, canIdentify,
7676
} = window.ImmutableAudience;
77-
const audience = Audience.init({
77+
const audience = init({
7878
publishableKey: 'pk_imapik-test-...',
7979
consent: 'anonymous',
8080
onError: (err) => console.error(err.code, err.message),
@@ -84,10 +84,11 @@ audience.shutdown();
8484
</script>
8585
```
8686

87-
The CDN bundle attaches the same runtime symbols that ESM consumers
88-
import — `Audience`, `AudienceError`, `AudienceEvents`, `IdentityType`,
89-
`canTrack`, `canIdentify`, and `version` — so no snippet is reachable
90-
on one path but not the other.
87+
The CDN bundle attaches `init` (the same static factory ESM consumers
88+
call as `Audience.init({...})`) alongside `AudienceError`,
89+
`AudienceEvents`, `IdentityType`, `canTrack`, `canIdentify`, and
90+
`version`, so every runtime helper an ESM consumer needs is reachable
91+
from the CDN global too.
9192

9293
## Error handling
9394

0 commit comments

Comments
 (0)