mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Enforce either userId or anonymousId as identifiers (#43633)
This commit is contained in:
parent
9922d95b74
commit
849d832831
@ -32,5 +32,6 @@
|
||||
"_comment": "This will remove husky from when we started migrating to use prettier",
|
||||
"pre-commit": "npm uninstall husky"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
31
types/analytics-node/index.d.ts
vendored
31
types/analytics-node/index.d.ts
vendored
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user