ugcinc 2.7.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/dist/stats.d.ts +114 -1
- package/dist/stats.js +119 -0
- package/dist/types.d.ts +56 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,8 +68,11 @@ For complete API documentation, including all endpoints, parameters, and example
|
|
|
68
68
|
- Delete tasks
|
|
69
69
|
|
|
70
70
|
### Statistics
|
|
71
|
-
- Get account statistics
|
|
72
|
-
- Get post statistics
|
|
71
|
+
- Get account statistics (latest or date range)
|
|
72
|
+
- Get post statistics (latest or date range)
|
|
73
|
+
- Get daily aggregated stats (for charts/dashboards)
|
|
74
|
+
- Get top accounts by metric (followers, views, likes, etc.)
|
|
75
|
+
- Get top posts by metric (views, likes, comments, etc.)
|
|
73
76
|
- Refresh statistics
|
|
74
77
|
|
|
75
78
|
### Organization
|
|
@@ -429,6 +432,58 @@ if (statusResponse.ok && statusResponse.data.status === 'completed') {
|
|
|
429
432
|
}
|
|
430
433
|
```
|
|
431
434
|
|
|
435
|
+
**Statistics:**
|
|
436
|
+
```typescript
|
|
437
|
+
// Get latest stats (one record per account/post)
|
|
438
|
+
const latestAccountStats = await client.stats.getAccountStats();
|
|
439
|
+
const latestPostStats = await client.stats.getPostStats();
|
|
440
|
+
|
|
441
|
+
// Get stats for a date range
|
|
442
|
+
const rangeStats = await client.stats.getAccountStats({
|
|
443
|
+
startDate: '2024-01-01',
|
|
444
|
+
endDate: '2024-01-31',
|
|
445
|
+
tag: 'fitness'
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// Get daily aggregated stats for charts
|
|
449
|
+
const dailyStats = await client.stats.getDailyAggregated({
|
|
450
|
+
startDate: '2024-01-01',
|
|
451
|
+
endDate: '2024-01-31',
|
|
452
|
+
org_group: 'group1'
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
if (dailyStats.ok) {
|
|
456
|
+
dailyStats.data.forEach(day => {
|
|
457
|
+
console.log(`${day.date}: +${day.followers} followers, +${day.views} views, ${day.posts} posts`);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Get top 5 accounts by followers
|
|
462
|
+
const topAccounts = await client.stats.getTopAccounts({
|
|
463
|
+
metric: 'followers',
|
|
464
|
+
limit: 5,
|
|
465
|
+
tag: 'fitness'
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// Get top 10 posts by views
|
|
469
|
+
const topPosts = await client.stats.getTopPosts({
|
|
470
|
+
metric: 'views',
|
|
471
|
+
limit: 10
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Refresh stats (fetch live data from platforms)
|
|
475
|
+
// Can only be called once per hour per organization
|
|
476
|
+
const refreshResult = await client.stats.refresh({
|
|
477
|
+
org_group: 'optional-group-filter'
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
if (refreshResult.ok) {
|
|
481
|
+
console.log(`Refreshed ${refreshResult.data.accounts_refreshed} accounts`);
|
|
482
|
+
console.log(`New account stats: ${refreshResult.data.account_stats.length}`);
|
|
483
|
+
console.log(`New post stats: ${refreshResult.data.post_stats.length}`);
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
432
487
|
## TypeScript Support
|
|
433
488
|
|
|
434
489
|
This package is written in TypeScript and provides full type definitions:
|
package/dist/stats.d.ts
CHANGED
|
@@ -1,17 +1,130 @@
|
|
|
1
1
|
import { BaseClient } from './base';
|
|
2
|
-
import type { AccountStat, PostStat, GetAccountStatsParams, GetPostStatsParams, RefreshStatsParams, RefreshStatsResponse, ApiResponse } from './types';
|
|
2
|
+
import type { AccountStat, PostStat, GetAccountStatsParams, GetPostStatsParams, RefreshStatsParams, RefreshStatsResponse, DailyAggregatedStat, GetDailyAggregatedStatsParams, TopAccount, GetTopAccountsParams, TopPost, GetTopPostsParams, ApiResponse } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Client for managing statistics
|
|
5
5
|
*/
|
|
6
6
|
export declare class StatsClient extends BaseClient {
|
|
7
7
|
/**
|
|
8
8
|
* Get account statistics
|
|
9
|
+
*
|
|
10
|
+
* **Behavior:**
|
|
11
|
+
* - If `startDate` and `endDate` are NOT provided: Returns the latest stat per account (one record per account)
|
|
12
|
+
* - If `startDate` or `endDate` is provided: Returns all stats within the date range
|
|
13
|
+
*
|
|
14
|
+
* @param params - Optional filter parameters
|
|
15
|
+
* @returns Array of account statistics
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Get latest stats for all accounts
|
|
20
|
+
* const latest = await client.stats.getAccountStats();
|
|
21
|
+
*
|
|
22
|
+
* // Get stats for a date range
|
|
23
|
+
* const range = await client.stats.getAccountStats({
|
|
24
|
+
* startDate: '2024-01-01',
|
|
25
|
+
* endDate: '2024-01-31'
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
9
28
|
*/
|
|
10
29
|
getAccountStats(params?: GetAccountStatsParams): Promise<ApiResponse<AccountStat[]>>;
|
|
11
30
|
/**
|
|
12
31
|
* Get post statistics
|
|
32
|
+
*
|
|
33
|
+
* **Behavior:**
|
|
34
|
+
* - If `startDate` and `endDate` are NOT provided: Returns the latest stat per post (one record per post)
|
|
35
|
+
* - If `startDate` or `endDate` is provided: Returns all stats within the date range
|
|
36
|
+
*
|
|
37
|
+
* @param params - Optional filter parameters
|
|
38
|
+
* @returns Array of post statistics
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Get latest stats for all posts
|
|
43
|
+
* const latest = await client.stats.getPostStats();
|
|
44
|
+
*
|
|
45
|
+
* // Get stats for a date range
|
|
46
|
+
* const range = await client.stats.getPostStats({
|
|
47
|
+
* startDate: '2024-01-01',
|
|
48
|
+
* endDate: '2024-01-31'
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
13
51
|
*/
|
|
14
52
|
getPostStats(params?: GetPostStatsParams): Promise<ApiResponse<PostStat[]>>;
|
|
53
|
+
/**
|
|
54
|
+
* Get daily aggregated statistics for dashboard charts
|
|
55
|
+
*
|
|
56
|
+
* Returns one record per day with total changes across all filtered accounts.
|
|
57
|
+
* Perfect for rendering time-series charts showing growth over time.
|
|
58
|
+
*
|
|
59
|
+
* @param params - Date range and filter parameters (startDate and endDate required)
|
|
60
|
+
* @returns Array of daily aggregated statistics
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const dailyStats = await client.stats.getDailyAggregated({
|
|
65
|
+
* startDate: '2024-01-01',
|
|
66
|
+
* endDate: '2024-01-31',
|
|
67
|
+
* tag: 'fitness'
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Use for charts
|
|
71
|
+
* dailyStats.data.forEach(day => {
|
|
72
|
+
* console.log(`${day.date}: +${day.followers} followers, +${day.views} views`);
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
getDailyAggregated(params: GetDailyAggregatedStatsParams): Promise<ApiResponse<DailyAggregatedStat[]>>;
|
|
77
|
+
/**
|
|
78
|
+
* Get top N accounts by a specific metric
|
|
79
|
+
*
|
|
80
|
+
* Returns the highest-performing accounts based on the selected metric.
|
|
81
|
+
* Uses the latest stats for each account.
|
|
82
|
+
*
|
|
83
|
+
* @param params - Metric and filter parameters
|
|
84
|
+
* @returns Array of top accounts sorted by the metric
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Get top 5 accounts by followers
|
|
89
|
+
* const topByFollowers = await client.stats.getTopAccounts({
|
|
90
|
+
* metric: 'followers',
|
|
91
|
+
* limit: 5
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // Get top 10 accounts by views in a specific tag
|
|
95
|
+
* const topByViews = await client.stats.getTopAccounts({
|
|
96
|
+
* metric: 'views',
|
|
97
|
+
* limit: 10,
|
|
98
|
+
* tag: 'fitness'
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
getTopAccounts(params: GetTopAccountsParams): Promise<ApiResponse<TopAccount[]>>;
|
|
103
|
+
/**
|
|
104
|
+
* Get top N posts by a specific metric
|
|
105
|
+
*
|
|
106
|
+
* Returns the highest-performing posts based on the selected metric.
|
|
107
|
+
* Uses the latest stats for each post.
|
|
108
|
+
*
|
|
109
|
+
* @param params - Metric and filter parameters
|
|
110
|
+
* @returns Array of top posts sorted by the metric
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // Get top 5 posts by views
|
|
115
|
+
* const topByViews = await client.stats.getTopPosts({
|
|
116
|
+
* metric: 'views',
|
|
117
|
+
* limit: 5
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Get top 10 posts by likes
|
|
121
|
+
* const topByLikes = await client.stats.getTopPosts({
|
|
122
|
+
* metric: 'likes',
|
|
123
|
+
* limit: 10
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
getTopPosts(params: GetTopPostsParams): Promise<ApiResponse<TopPost[]>>;
|
|
15
128
|
/**
|
|
16
129
|
* Refresh statistics for all accounts in the organization (optionally filtered by org_group)
|
|
17
130
|
* Fetches live data from TikTok/Instagram API and creates new stat records
|
package/dist/stats.js
CHANGED
|
@@ -8,16 +8,135 @@ const base_1 = require("./base");
|
|
|
8
8
|
class StatsClient extends base_1.BaseClient {
|
|
9
9
|
/**
|
|
10
10
|
* Get account statistics
|
|
11
|
+
*
|
|
12
|
+
* **Behavior:**
|
|
13
|
+
* - If `startDate` and `endDate` are NOT provided: Returns the latest stat per account (one record per account)
|
|
14
|
+
* - If `startDate` or `endDate` is provided: Returns all stats within the date range
|
|
15
|
+
*
|
|
16
|
+
* @param params - Optional filter parameters
|
|
17
|
+
* @returns Array of account statistics
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Get latest stats for all accounts
|
|
22
|
+
* const latest = await client.stats.getAccountStats();
|
|
23
|
+
*
|
|
24
|
+
* // Get stats for a date range
|
|
25
|
+
* const range = await client.stats.getAccountStats({
|
|
26
|
+
* startDate: '2024-01-01',
|
|
27
|
+
* endDate: '2024-01-31'
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
11
30
|
*/
|
|
12
31
|
async getAccountStats(params) {
|
|
13
32
|
return this.post('/stats/accounts', params ?? {});
|
|
14
33
|
}
|
|
15
34
|
/**
|
|
16
35
|
* Get post statistics
|
|
36
|
+
*
|
|
37
|
+
* **Behavior:**
|
|
38
|
+
* - If `startDate` and `endDate` are NOT provided: Returns the latest stat per post (one record per post)
|
|
39
|
+
* - If `startDate` or `endDate` is provided: Returns all stats within the date range
|
|
40
|
+
*
|
|
41
|
+
* @param params - Optional filter parameters
|
|
42
|
+
* @returns Array of post statistics
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Get latest stats for all posts
|
|
47
|
+
* const latest = await client.stats.getPostStats();
|
|
48
|
+
*
|
|
49
|
+
* // Get stats for a date range
|
|
50
|
+
* const range = await client.stats.getPostStats({
|
|
51
|
+
* startDate: '2024-01-01',
|
|
52
|
+
* endDate: '2024-01-31'
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
17
55
|
*/
|
|
18
56
|
async getPostStats(params) {
|
|
19
57
|
return this.post('/stats/posts', params ?? {});
|
|
20
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Get daily aggregated statistics for dashboard charts
|
|
61
|
+
*
|
|
62
|
+
* Returns one record per day with total changes across all filtered accounts.
|
|
63
|
+
* Perfect for rendering time-series charts showing growth over time.
|
|
64
|
+
*
|
|
65
|
+
* @param params - Date range and filter parameters (startDate and endDate required)
|
|
66
|
+
* @returns Array of daily aggregated statistics
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const dailyStats = await client.stats.getDailyAggregated({
|
|
71
|
+
* startDate: '2024-01-01',
|
|
72
|
+
* endDate: '2024-01-31',
|
|
73
|
+
* tag: 'fitness'
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Use for charts
|
|
77
|
+
* dailyStats.data.forEach(day => {
|
|
78
|
+
* console.log(`${day.date}: +${day.followers} followers, +${day.views} views`);
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
async getDailyAggregated(params) {
|
|
83
|
+
return this.post('/stats/aggregated/daily', params);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get top N accounts by a specific metric
|
|
87
|
+
*
|
|
88
|
+
* Returns the highest-performing accounts based on the selected metric.
|
|
89
|
+
* Uses the latest stats for each account.
|
|
90
|
+
*
|
|
91
|
+
* @param params - Metric and filter parameters
|
|
92
|
+
* @returns Array of top accounts sorted by the metric
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Get top 5 accounts by followers
|
|
97
|
+
* const topByFollowers = await client.stats.getTopAccounts({
|
|
98
|
+
* metric: 'followers',
|
|
99
|
+
* limit: 5
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Get top 10 accounts by views in a specific tag
|
|
103
|
+
* const topByViews = await client.stats.getTopAccounts({
|
|
104
|
+
* metric: 'views',
|
|
105
|
+
* limit: 10,
|
|
106
|
+
* tag: 'fitness'
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
async getTopAccounts(params) {
|
|
111
|
+
return this.post('/stats/aggregated/top-accounts', params);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get top N posts by a specific metric
|
|
115
|
+
*
|
|
116
|
+
* Returns the highest-performing posts based on the selected metric.
|
|
117
|
+
* Uses the latest stats for each post.
|
|
118
|
+
*
|
|
119
|
+
* @param params - Metric and filter parameters
|
|
120
|
+
* @returns Array of top posts sorted by the metric
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Get top 5 posts by views
|
|
125
|
+
* const topByViews = await client.stats.getTopPosts({
|
|
126
|
+
* metric: 'views',
|
|
127
|
+
* limit: 5
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Get top 10 posts by likes
|
|
131
|
+
* const topByLikes = await client.stats.getTopPosts({
|
|
132
|
+
* metric: 'likes',
|
|
133
|
+
* limit: 10
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
async getTopPosts(params) {
|
|
138
|
+
return this.post('/stats/aggregated/top-posts', params);
|
|
139
|
+
}
|
|
21
140
|
/**
|
|
22
141
|
* Refresh statistics for all accounts in the organization (optionally filtered by org_group)
|
|
23
142
|
* Fetches live data from TikTok/Instagram API and creates new stat records
|
package/dist/types.d.ts
CHANGED
|
@@ -219,6 +219,62 @@ export interface RefreshStatsResponse {
|
|
|
219
219
|
post_stats_count: number;
|
|
220
220
|
errors?: RefreshStatsError[];
|
|
221
221
|
}
|
|
222
|
+
export interface DailyAggregatedStat {
|
|
223
|
+
date: Date | string;
|
|
224
|
+
followers: number;
|
|
225
|
+
following: number;
|
|
226
|
+
views: number;
|
|
227
|
+
likes: number;
|
|
228
|
+
posts: number;
|
|
229
|
+
}
|
|
230
|
+
export interface GetDailyAggregatedStatsParams {
|
|
231
|
+
startDate: string;
|
|
232
|
+
endDate: string;
|
|
233
|
+
accountIds?: string[];
|
|
234
|
+
tag?: string;
|
|
235
|
+
org_group?: string;
|
|
236
|
+
user_group?: string;
|
|
237
|
+
}
|
|
238
|
+
export interface TopAccount {
|
|
239
|
+
account_id: string;
|
|
240
|
+
username: string | null;
|
|
241
|
+
nick_name: string | null;
|
|
242
|
+
pfp_url: string | null;
|
|
243
|
+
type: string;
|
|
244
|
+
tag: string | null;
|
|
245
|
+
followers: number | null;
|
|
246
|
+
following: number | null;
|
|
247
|
+
views: number | null;
|
|
248
|
+
likes: number | null;
|
|
249
|
+
created_at: string;
|
|
250
|
+
}
|
|
251
|
+
export interface GetTopAccountsParams {
|
|
252
|
+
metric: 'followers' | 'following' | 'views' | 'likes';
|
|
253
|
+
limit?: number;
|
|
254
|
+
accountIds?: string[];
|
|
255
|
+
tag?: string;
|
|
256
|
+
org_group?: string;
|
|
257
|
+
user_group?: string;
|
|
258
|
+
}
|
|
259
|
+
export interface TopPost {
|
|
260
|
+
post_id: string;
|
|
261
|
+
account_id: string;
|
|
262
|
+
caption: string | null;
|
|
263
|
+
media_urls: string[] | null;
|
|
264
|
+
type: string;
|
|
265
|
+
social_id: string | null;
|
|
266
|
+
views: number | null;
|
|
267
|
+
likes: number | null;
|
|
268
|
+
comments: number | null;
|
|
269
|
+
shares: number | null;
|
|
270
|
+
saves: number | null;
|
|
271
|
+
created_at: string;
|
|
272
|
+
}
|
|
273
|
+
export interface GetTopPostsParams {
|
|
274
|
+
metric: 'views' | 'likes' | 'comments' | 'shares' | 'saves';
|
|
275
|
+
limit?: number;
|
|
276
|
+
postIds?: string[];
|
|
277
|
+
}
|
|
222
278
|
/**
|
|
223
279
|
* Organization and API Key types
|
|
224
280
|
*/
|