Enforce either userId or anonymousId as identifiers (#43633)

This commit is contained in:
Zhang Yi Jiang 2020-04-06 19:23:10 -07:00 committed by GitHub
parent 9922d95b74
commit 849d832831
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 20 deletions

View File

@ -32,5 +32,6 @@
"_comment": "This will remove husky from when we started migrating to use prettier",
"pre-commit": "npm uninstall husky"
}
}
},
"dependencies": {}
}

View File

@ -59,6 +59,24 @@ function testTrack(): void {
}
});
analytics.track({
anonymousId: '019mr8mf4r',
event: 'Purchased an Item',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
// $ExpectError
analytics.track({
event: 'Purchased an Item',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
analytics.track({
userId: '019mr8mf4r',
event: 'Purchased an Item',

View File

@ -3,11 +3,16 @@
// Definitions by: Andrew Fong <https://github.com/fongandrew>
// Thomas Thiebaud <https://github.com/thomasthiebaud>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export = AnalyticsNode.Analytics;
declare namespace AnalyticsNode {
interface Message {
type Identity =
| { userId: string | number }
| { userId?: string | number; anonymousId: string | number };
type Message = Identity & {
type: string;
context: {
library: {
@ -22,9 +27,7 @@ declare namespace AnalyticsNode {
};
timestamp?: Date;
messageId?: string;
anonymousId?: string | number;
userId?: string | number;
}
};
interface Data {
batch: Message[];
@ -49,9 +52,7 @@ declare namespace AnalyticsNode {
/* The identify method lets you tie a user to their actions and record
traits about them. */
identify(message: {
userId?: string | number;
anonymousId?: string | number;
identify(message: Identity & {
traits?: any;
timestamp?: Date;
context?: any;
@ -59,9 +60,7 @@ declare namespace AnalyticsNode {
}, callback?: (err: Error, data: Data) => void): Analytics;
/* The track method lets you record the actions your users perform. */
track(message: {
userId?: string | number;
anonymousId?: string | number;
track(message: Identity & {
event: string;
properties?: any;
timestamp?: Date;
@ -71,9 +70,7 @@ declare namespace AnalyticsNode {
/* The page method lets you record page views on your website, along with
optional extra information about the page being viewed. */
page(message: {
userId?: string | number;
anonymousId?: string | number;
page(message: Identity & {
category?: string;
name?: string;
properties?: any;
@ -83,18 +80,14 @@ declare namespace AnalyticsNode {
}, callback?: (err: Error, data: Data) => void): Analytics;
/* alias is how you associate one identity with another. */
alias(message: {
alias(message: Identity & {
previousId: string | number;
userId?: string | number;
anonymousId?: string | number;
integrations?: Integrations;
}, callback?: (err: Error, data: Data) => void): Analytics;
/* Group calls can be used to associate individual users with shared
accounts or companies. */
group(message: {
userId?: string | number;
anonymousId?: string | number;
group(message: Identity & {
groupId: string | number;
traits?: any;
context?: any;