diff --git a/index.ts b/index.ts index 7091f211..fc10a413 100644 --- a/index.ts +++ b/index.ts @@ -8,7 +8,7 @@ let isOneSignalInitialized = false; // OneSignal#init. let isOneSignalScriptFailed = false; -window.OneSignalDeferred = window.OneSignalDeferred || []; +window.OneSignalDeferred = window?.OneSignalDeferred || []; addSDKScript(); @@ -190,6 +190,10 @@ interface IOneSignalUser { removeEmail(email: string): void; addSms(smsNumber: string): void; removeSms(smsNumber: string): void; + addTag(key: string, value: string): void; + addTags(tags: { [key: string]: string }): void; + removeTag(key: string): void; + removeTags(keys: string[]): void; } interface IOneSignalPushSubscription { id: string | null | undefined; @@ -551,6 +555,30 @@ function userRemoveSms(smsNumber: string): void { }); } +function userAddTag(key: string, value: string): void { + window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => { + OneSignal.User.addTag(key, value) + }); +} + +function userAddTags(tags: { [key: string]: string }): void { + window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => { + OneSignal.User.addTags(tags) + }); +} + +function userRemoveTag(key: string): void { + window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => { + OneSignal.User.removeTag(key) + }); +} + +function userRemoveTags(keys: string[]): void { + window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => { + OneSignal.User.removeTags(keys) + }); +} + function pushSubscriptionOptIn(): Promise { return new Promise((resolve, reject) => { if (isOneSignalScriptFailed) { @@ -623,6 +651,10 @@ const UserNamespace: IOneSignalUser = { removeEmail: userRemoveEmail, addSms: userAddSms, removeSms: userRemoveSms, + addTag: userAddTag, + addTags: userAddTags, + removeTag: userRemoveTag, + removeTags: userRemoveTags, PushSubscription: PushSubscriptionNamespace, }; diff --git a/package.json b/package.json index 455d6f38..ef63215f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-onesignal", - "version": "3.0.0-beta.2", + "version": "3.0.0-beta.3", "description": "React OneSignal Module: Make it easy to integrate OneSignal with your React App!", "author": "rgomezp", "contributors": [{ "name": "Rodrigo Gomez-Palacio" }, { "name": "Pedro Bini" }, { "name": "Graham Marlow" }],