Add Custom Events#1336
Conversation
56e3bb5 to
b3ff042
Compare
ed3bc3a to
b7a9b6d
Compare
| model.sdk = sub.sdk; | ||
| model.device_os = sub.device_os; | ||
| model.device_model = sub.device_model; |
There was a problem hiding this comment.
does this mean if any of these values are missing, they will get saved/sent as undefined?
There was a problem hiding this comment.
refresh call should have the sdk, device_os and device_module information
There was a problem hiding this comment.
Also updated device_os to be a string.
| get timestamp(): string { | ||
| return this.getProperty('timestamp'); | ||
| } | ||
| private set timestamp(value: string) { |
There was a problem hiding this comment.
should this default to now()?
There was a problem hiding this comment.
We set a custom iso string from the caller
| /** | ||
| * Lists all aliases for the user identified by the given subscription id | ||
| * @param requestMetadata - { appId } | ||
| * @param subscriptionId - subscription id | ||
| */ | ||
| static async getIdentityFromSubscription( | ||
| requestMetadata: RequestMetadata, | ||
| subscriptionId: string, | ||
| ) { | ||
| const { appId } = requestMetadata; | ||
| return OneSignalApiBase.get<{ identity: IUserIdentity }>( | ||
| `apps/${appId}/subscriptions/${subscriptionId}/user/identity`, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Upserts one or more aliases for the user identified by the given subscription id | ||
| * @param requestMetadata - { appId } | ||
| * @param subscriptionId - subscription id | ||
| * @param identity - identity label & id | ||
| */ | ||
| static async identifyUserForSubscription( | ||
| requestMetadata: RequestMetadata, | ||
| subscriptionId: string, | ||
| identity: IdentityModel, | ||
| ): Promise<OneSignalApiBaseResponse> { | ||
| const { appId } = requestMetadata; | ||
| return OneSignalApiBase.patch<{ identity: IUserIdentity }>( | ||
| `apps/${appId}/users/by/subscriptions/${subscriptionId}/identity`, | ||
| { identity }, | ||
| requestMetadata.jwtHeader, | ||
| ); | ||
| } | ||
|
|
b7a9b6d to
f542664
Compare
| export const getSubscriptionType = (): SubscriptionTypeValue => { | ||
| const browser = OneSignalUtils.redetectBrowserUserAgent(); | ||
| if (browser.firefox) { | ||
| return SubscriptionType.FirefoxPush; | ||
| } | ||
| if (useSafariVapidPush()) { | ||
| return SubscriptionType.SafariPush; | ||
| } | ||
| if (useSafariLegacyPush) { | ||
| return SubscriptionType.SafariLegacyPush; | ||
| } | ||
| // Other browsers, like Edge, are Chromium based so we consider them "Chrome". | ||
| return SubscriptionType.ChromePush; | ||
| }; | ||
|
|
||
| /** | ||
| * Get the legacy player.device_type | ||
| * NOTE: Use getSubscriptionType() instead when possible. | ||
| */ | ||
| export function getDeviceType(): DeliveryPlatformKindValue { | ||
| switch (getSubscriptionType()) { | ||
| case SubscriptionType.FirefoxPush: | ||
| return DeliveryPlatformKind.Firefox; | ||
| case SubscriptionType.SafariLegacyPush: | ||
| return DeliveryPlatformKind.SafariLegacy; | ||
| case SubscriptionType.SafariPush: | ||
| return DeliveryPlatformKind.SafariVapid; | ||
| } | ||
| return DeliveryPlatformKind.ChromeLike; | ||
| } | ||
|
|
||
| export function getDeviceOS(): string { | ||
| const environment = EnvironmentInfoHelper.getEnvironmentInfo(); | ||
| return String( | ||
| isNaN(environment.browserVersion) ? -1 : environment.browserVersion, | ||
| ); | ||
| } | ||
|
|
||
| export function getDeviceModel(): string { | ||
| return navigator.platform; | ||
| } |
There was a problem hiding this comment.
I'm not sure I follow: why was this moved from FuturePushSubscriptionRecord?
There was a problem hiding this comment.
Because its used in multiple places like custom events and subscription op
flesh out the track event operation and create custom logic add tests for custom events add subscription type for custom events
5ef1467 to
a23271a
Compare
a23271a to
1eccea5
Compare
|
If I enqueue a |
|
Sending a custom event without a |
09132b1 to
9d1cf40
Compare
Should be fixed now |
Try it now |
9d1cf40 to
f13ff4a
Compare
set local id for identity if it doesnt exist, allow to execut after login is called
f13ff4a to
b2d4239
Compare
3ef0768 to
f5930c6
Compare
| override get createComparisonKey(): string { | ||
| return this.key; | ||
| } | ||
| override get modifyComparisonKey(): string { | ||
| return this.key; |
There was a problem hiding this comment.
createComparisonKey and modifyComparisonKey should both be nothing (aka empty string). Having this set to a value can be misleading or confusing down the line if someone was trying to figure out how we were using these keys to batch. It is effectively no different than using a random UUID.
If we do batch in the future, it'll probably be more like ${this.appId}.User.${this.onesignalId}.CustomEvent dropping the name identifier and batch per user.
There was a problem hiding this comment.
In our meeting, we said this is fine for now.
f5930c6 to
ef9371d
Compare
ef9371d to
782513f
Compare
add more test cases
782513f to
17508b2
Compare
bdef986 to
085cd1d
Compare
Description
1 Line Summary
Add custom events logic for the web sdk.
Reference docs:
Details
getDeviceOSandgetDeviceModelto Environment classsendCustomEventrequest service helperdevice_ostypes to just be a string/undefinedresetUserModelsto update operation local onesignal ids to new local onesignal ids if valid. This is for situations we call trackEvent before login where trackEvent sets a localid but login resets the ids again so we need to update the previous ids. Since we only check for local id, if user was already create thentrackEvent; login;for an existing user should use different ids.currentOneSignalIdif its local since login op wont execute for cases we call trackEvent then login.Systems Affected
Screenshots
Validation
Tests
Add tests cases for UserNamespace as well OneSignal.test cases for calling track.
Can test manually by setting app id to Mikes Test App. And setting port to 4001 for vite.config.
Info
Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of arraysyntax. PreferforEachor usemapcontextif possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.contextInfo
Checklist
Related Tickets
This change is