Skip to content

Commit 656b6c6

Browse files
committed
Change analytics method to be arrow functions in order to be bound to the instance
1 parent 8ef3f79 commit 656b6c6

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

packages/analytics-nextjs/src/Analytics.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class Analytics {
8686
}
8787
}
8888

89-
public async init(config: Config) {
89+
public init = async (config: Config) => {
9090
if (this.config) {
9191
// Cannot re-initialize analytics
9292
return;
@@ -126,7 +126,7 @@ export class Analytics {
126126
}
127127

128128
this.checkInitialized();
129-
}
129+
};
130130

131131
private async loadSegment() {
132132
if (this.config?.segment === false) {
@@ -159,9 +159,9 @@ export class Analytics {
159159
);
160160
}
161161

162-
public setMeta(meta: PrezlyMeta) {
162+
public setMeta = (meta: PrezlyMeta) => {
163163
this._meta = meta;
164-
}
164+
};
165165

166166
private get meta() {
167167
if (!this._meta) {
@@ -171,7 +171,7 @@ export class Analytics {
171171
return this._meta;
172172
}
173173

174-
public setConsent(consent: Consent) {
174+
public setConsent = (consent: Consent) => {
175175
if (!this.config) {
176176
throw new Error('Cannot set consent before analytics initialization');
177177
}
@@ -216,20 +216,20 @@ export class Analytics {
216216
});
217217

218218
this.checkInitialized();
219-
}
219+
};
220220

221-
public async alias(userId: string, previousId: string) {
221+
public alias = async (userId: string, previousId: string) => {
222222
await this.promises.init;
223223
await this.promises.segmentInit;
224224
await this.segment?.alias(userId, previousId, { integrations: this.integrations });
225-
}
225+
};
226226

227-
public async page(
227+
public page = async (
228228
category?: string,
229229
name?: string,
230230
properties: object = {},
231231
callback?: () => void,
232-
) {
232+
) => {
233233
await this.promises.init;
234234
await this.promises.segmentInit;
235235
await this.segment?.page(
@@ -239,9 +239,9 @@ export class Analytics {
239239
{ integrations: this.integrations },
240240
callback,
241241
);
242-
}
242+
};
243243

244-
public async track(event: string, properties: object = {}, callback?: () => void) {
244+
public track = async (event: string, properties: object = {}, callback?: () => void) => {
245245
const props = this.meta ? { ...properties, prezly: this.meta } : properties;
246246

247247
await this.promises.init;
@@ -256,9 +256,9 @@ export class Analytics {
256256
this.segment?.track(event, props, { integrations: this.integrations }, callback),
257257
),
258258
]);
259-
}
259+
};
260260

261-
public async identify(userId: string, traits: object = {}, callback?: () => void) {
261+
public identify = async (userId: string, traits: object = {}, callback?: () => void) => {
262262
this.identity = { userId, traits };
263263

264264
await this.promises.init;
@@ -272,7 +272,7 @@ export class Analytics {
272272
callback,
273273
);
274274
}
275-
}
275+
};
276276

277277
public user() {
278278
return this.segment?.instance?.user() ?? NULL_USER;

0 commit comments

Comments
 (0)