@memberjunction/actions-bizapps-social 2.111.0 → 2.112.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -6
- package/dist/base/base-social.action.d.ts.map +1 -1
- package/dist/base/base-social.action.js +18 -24
- package/dist/base/base-social.action.js.map +1 -1
- package/dist/providers/buffer/buffer-base.action.d.ts.map +1 -1
- package/dist/providers/buffer/buffer-base.action.js +35 -34
- package/dist/providers/buffer/buffer-base.action.js.map +1 -1
- package/dist/providers/facebook/actions/boost-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/boost-post.action.js +33 -33
- package/dist/providers/facebook/actions/boost-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/create-album.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/create-album.action.js +34 -36
- package/dist/providers/facebook/actions/create-album.action.js.map +1 -1
- package/dist/providers/facebook/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/create-post.action.js +20 -20
- package/dist/providers/facebook/actions/create-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-page-insights.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-page-insights.action.js +25 -27
- package/dist/providers/facebook/actions/get-page-insights.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-page-posts.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-page-posts.action.js +19 -23
- package/dist/providers/facebook/actions/get-page-posts.action.js.map +1 -1
- package/dist/providers/facebook/actions/get-post-insights.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/get-post-insights.action.js +28 -32
- package/dist/providers/facebook/actions/get-post-insights.action.js.map +1 -1
- package/dist/providers/facebook/actions/respond-to-comments.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/respond-to-comments.action.js +42 -44
- package/dist/providers/facebook/actions/respond-to-comments.action.js.map +1 -1
- package/dist/providers/facebook/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/schedule-post.action.js +29 -29
- package/dist/providers/facebook/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/facebook/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/facebook/actions/search-posts.action.js +37 -39
- package/dist/providers/facebook/actions/search-posts.action.js.map +1 -1
- package/dist/providers/facebook/facebook-base.action.d.ts.map +1 -1
- package/dist/providers/facebook/facebook-base.action.js +44 -59
- package/dist/providers/facebook/facebook-base.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js +33 -31
- package/dist/providers/hootsuite/actions/bulk-schedule-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.js +28 -32
- package/dist/providers/hootsuite/actions/create-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js +19 -19
- package/dist/providers/hootsuite/actions/delete-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-analytics.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-analytics.action.js +24 -26
- package/dist/providers/hootsuite/actions/get-analytics.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js +22 -22
- package/dist/providers/hootsuite/actions/get-scheduled-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/get-social-profiles.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/get-social-profiles.action.js +32 -34
- package/dist/providers/hootsuite/actions/get-social-profiles.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/search-posts.action.js +43 -52
- package/dist/providers/hootsuite/actions/search-posts.action.js.map +1 -1
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.js +30 -28
- package/dist/providers/hootsuite/actions/update-scheduled-post.action.js.map +1 -1
- package/dist/providers/hootsuite/hootsuite-base.action.d.ts.map +1 -1
- package/dist/providers/hootsuite/hootsuite-base.action.js +18 -20
- package/dist/providers/hootsuite/hootsuite-base.action.js.map +1 -1
- package/dist/providers/instagram/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/create-post.action.js +27 -26
- package/dist/providers/instagram/actions/create-post.action.js.map +1 -1
- package/dist/providers/instagram/actions/create-story.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/create-story.action.js +35 -35
- package/dist/providers/instagram/actions/create-story.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-account-insights.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-account-insights.action.js +38 -59
- package/dist/providers/instagram/actions/get-account-insights.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-business-posts.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-business-posts.action.js +29 -29
- package/dist/providers/instagram/actions/get-business-posts.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-comments.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-comments.action.js +36 -36
- package/dist/providers/instagram/actions/get-comments.action.js.map +1 -1
- package/dist/providers/instagram/actions/get-post-insights.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/get-post-insights.action.js +23 -25
- package/dist/providers/instagram/actions/get-post-insights.action.js.map +1 -1
- package/dist/providers/instagram/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/schedule-post.action.js +25 -25
- package/dist/providers/instagram/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/instagram/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/instagram/actions/search-posts.action.js +56 -60
- package/dist/providers/instagram/actions/search-posts.action.js.map +1 -1
- package/dist/providers/instagram/instagram-base.action.d.ts.map +1 -1
- package/dist/providers/instagram/instagram-base.action.js +25 -27
- package/dist/providers/instagram/instagram-base.action.js.map +1 -1
- package/dist/providers/linkedin/actions/create-article.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/create-article.action.js +55 -45
- package/dist/providers/linkedin/actions/create-article.action.js.map +1 -1
- package/dist/providers/linkedin/actions/create-post.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/create-post.action.js +31 -29
- package/dist/providers/linkedin/actions/create-post.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-followers.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-followers.action.js +28 -28
- package/dist/providers/linkedin/actions/get-followers.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-organization-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-organization-posts.action.js +20 -20
- package/dist/providers/linkedin/actions/get-organization-posts.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-personal-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-personal-posts.action.js +19 -19
- package/dist/providers/linkedin/actions/get-personal-posts.action.js.map +1 -1
- package/dist/providers/linkedin/actions/get-post-analytics.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/get-post-analytics.action.js +25 -23
- package/dist/providers/linkedin/actions/get-post-analytics.action.js.map +1 -1
- package/dist/providers/linkedin/actions/schedule-post.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/schedule-post.action.js +32 -30
- package/dist/providers/linkedin/actions/schedule-post.action.js.map +1 -1
- package/dist/providers/linkedin/actions/search-posts.action.d.ts.map +1 -1
- package/dist/providers/linkedin/actions/search-posts.action.js +28 -30
- package/dist/providers/linkedin/actions/search-posts.action.js.map +1 -1
- package/dist/providers/linkedin/linkedin-base.action.d.ts.map +1 -1
- package/dist/providers/linkedin/linkedin-base.action.js +33 -38
- package/dist/providers/linkedin/linkedin-base.action.js.map +1 -1
- package/dist/providers/tiktok/tiktok-base.action.d.ts.map +1 -1
- package/dist/providers/tiktok/tiktok-base.action.js +25 -26
- package/dist/providers/tiktok/tiktok-base.action.js.map +1 -1
- package/dist/providers/twitter/actions/create-thread.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/create-thread.action.js +25 -29
- package/dist/providers/twitter/actions/create-thread.action.js.map +1 -1
- package/dist/providers/twitter/actions/create-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/create-tweet.action.js +23 -23
- package/dist/providers/twitter/actions/create-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/delete-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/delete-tweet.action.js +19 -19
- package/dist/providers/twitter/actions/delete-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-analytics.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-analytics.action.js +40 -47
- package/dist/providers/twitter/actions/get-analytics.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-mentions.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-mentions.action.js +30 -31
- package/dist/providers/twitter/actions/get-mentions.action.js.map +1 -1
- package/dist/providers/twitter/actions/get-timeline.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/get-timeline.action.js +29 -29
- package/dist/providers/twitter/actions/get-timeline.action.js.map +1 -1
- package/dist/providers/twitter/actions/schedule-tweet.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/schedule-tweet.action.js +26 -26
- package/dist/providers/twitter/actions/schedule-tweet.action.js.map +1 -1
- package/dist/providers/twitter/actions/search-tweets.action.d.ts.map +1 -1
- package/dist/providers/twitter/actions/search-tweets.action.js +56 -58
- package/dist/providers/twitter/actions/search-tweets.action.js.map +1 -1
- package/dist/providers/twitter/twitter-base.action.d.ts.map +1 -1
- package/dist/providers/twitter/twitter-base.action.js +58 -68
- package/dist/providers/twitter/twitter-base.action.js.map +1 -1
- package/dist/providers/youtube/youtube-base.action.d.ts +1 -1
- package/dist/providers/youtube/youtube-base.action.d.ts.map +1 -1
- package/dist/providers/youtube/youtube-base.action.js +22 -25
- package/dist/providers/youtube/youtube-base.action.js.map +1 -1
- package/package.json +5 -6
- package/src/base/base-social.action.ts +217 -224
- package/src/providers/buffer/buffer-base.action.ts +435 -441
- package/src/providers/facebook/actions/boost-post.action.ts +350 -386
- package/src/providers/facebook/actions/create-album.action.ts +291 -307
- package/src/providers/facebook/actions/create-post.action.ts +224 -227
- package/src/providers/facebook/actions/get-page-insights.action.ts +383 -403
- package/src/providers/facebook/actions/get-page-posts.action.ts +214 -225
- package/src/providers/facebook/actions/get-post-insights.action.ts +300 -316
- package/src/providers/facebook/actions/respond-to-comments.action.ts +319 -336
- package/src/providers/facebook/actions/schedule-post.action.ts +289 -292
- package/src/providers/facebook/actions/search-posts.action.ts +399 -413
- package/src/providers/facebook/facebook-base.action.ts +653 -670
- package/src/providers/hootsuite/actions/bulk-schedule-posts.action.ts +257 -257
- package/src/providers/hootsuite/actions/create-scheduled-post.action.ts +184 -189
- package/src/providers/hootsuite/actions/delete-scheduled-post.action.ts +160 -161
- package/src/providers/hootsuite/actions/get-analytics.action.ts +249 -254
- package/src/providers/hootsuite/actions/get-scheduled-posts.action.ts +206 -207
- package/src/providers/hootsuite/actions/get-social-profiles.action.ts +206 -205
- package/src/providers/hootsuite/actions/search-posts.action.ts +351 -369
- package/src/providers/hootsuite/actions/update-scheduled-post.action.ts +211 -209
- package/src/providers/hootsuite/hootsuite-base.action.ts +301 -307
- package/src/providers/instagram/actions/create-post.action.ts +276 -296
- package/src/providers/instagram/actions/create-story.action.ts +378 -394
- package/src/providers/instagram/actions/get-account-insights.action.ts +384 -420
- package/src/providers/instagram/actions/get-business-posts.action.ts +233 -242
- package/src/providers/instagram/actions/get-comments.action.ts +365 -377
- package/src/providers/instagram/actions/get-post-insights.action.ts +265 -273
- package/src/providers/instagram/actions/schedule-post.action.ts +233 -235
- package/src/providers/instagram/actions/search-posts.action.ts +512 -538
- package/src/providers/instagram/instagram-base.action.ts +368 -393
- package/src/providers/linkedin/actions/create-article.action.ts +275 -266
- package/src/providers/linkedin/actions/create-post.action.ts +179 -177
- package/src/providers/linkedin/actions/get-followers.action.ts +211 -211
- package/src/providers/linkedin/actions/get-organization-posts.action.ts +146 -147
- package/src/providers/linkedin/actions/get-personal-posts.action.ts +138 -139
- package/src/providers/linkedin/actions/get-post-analytics.action.ts +190 -189
- package/src/providers/linkedin/actions/schedule-post.action.ts +191 -189
- package/src/providers/linkedin/actions/search-posts.action.ts +275 -283
- package/src/providers/linkedin/linkedin-base.action.ts +407 -421
- package/src/providers/tiktok/tiktok-base.action.ts +305 -320
- package/src/providers/twitter/actions/create-thread.action.ts +203 -207
- package/src/providers/twitter/actions/create-tweet.action.ts +187 -188
- package/src/providers/twitter/actions/delete-tweet.action.ts +128 -129
- package/src/providers/twitter/actions/get-analytics.action.ts +402 -411
- package/src/providers/twitter/actions/get-mentions.action.ts +218 -219
- package/src/providers/twitter/actions/get-timeline.action.ts +232 -233
- package/src/providers/twitter/actions/schedule-tweet.action.ts +221 -222
- package/src/providers/twitter/actions/search-tweets.action.ts +540 -543
- package/src/providers/twitter/twitter-base.action.ts +541 -560
- package/src/providers/youtube/youtube-base.action.ts +320 -333
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RegisterClass } from '@memberjunction/global';
|
|
2
2
|
import { HootSuiteBaseAction, HootSuiteAnalytics } from '../hootsuite-base.action';
|
|
3
3
|
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
-
import { LogStatus, LogError } from '@memberjunction/
|
|
4
|
+
import { LogStatus, LogError } from '@memberjunction/global';
|
|
5
5
|
import { SocialAnalytics } from '../../../base/base-social.action';
|
|
6
6
|
import { BaseAction } from '@memberjunction/actions';
|
|
7
7
|
|
|
@@ -10,273 +10,268 @@ import { BaseAction } from '@memberjunction/actions';
|
|
|
10
10
|
*/
|
|
11
11
|
@RegisterClass(BaseAction, 'HootSuiteGetAnalyticsAction')
|
|
12
12
|
export class HootSuiteGetAnalyticsAction extends HootSuiteBaseAction {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
// Initialize OAuth
|
|
21
|
-
const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID');
|
|
22
|
-
if (!await this.initializeOAuth(companyIntegrationId)) {
|
|
23
|
-
throw new Error('Failed to initialize OAuth connection');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Extract parameters
|
|
27
|
-
const postId = this.getParamValue(Params, 'PostID');
|
|
28
|
-
const profileId = this.getParamValue(Params, 'ProfileID');
|
|
29
|
-
const startDate = this.getParamValue(Params, 'StartDate');
|
|
30
|
-
const endDate = this.getParamValue(Params, 'EndDate');
|
|
31
|
-
const metricsType = this.getParamValue(Params, 'MetricsType') || 'all';
|
|
32
|
-
const aggregateByProfile = this.getParamValue(Params, 'AggregateByProfile') || false;
|
|
33
|
-
|
|
34
|
-
// Determine what analytics to fetch
|
|
35
|
-
let analyticsData: any;
|
|
36
|
-
|
|
37
|
-
if (postId) {
|
|
38
|
-
// Get analytics for specific post
|
|
39
|
-
analyticsData = await this.getPostAnalytics(postId, startDate, endDate);
|
|
40
|
-
} else if (profileId) {
|
|
41
|
-
// Get analytics for specific profile
|
|
42
|
-
analyticsData = await this.getProfileAnalytics(profileId, startDate, endDate, metricsType);
|
|
43
|
-
} else {
|
|
44
|
-
// Get analytics for all profiles
|
|
45
|
-
analyticsData = await this.getAllProfilesAnalytics(startDate, endDate, metricsType, aggregateByProfile);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Normalize analytics
|
|
49
|
-
const normalizedAnalytics = this.processAnalyticsData(analyticsData, metricsType);
|
|
50
|
-
|
|
51
|
-
// Create summary
|
|
52
|
-
const summary = {
|
|
53
|
-
period: {
|
|
54
|
-
start: startDate || 'Not specified',
|
|
55
|
-
end: endDate || 'Not specified'
|
|
56
|
-
},
|
|
57
|
-
metricsType: metricsType,
|
|
58
|
-
totalMetrics: this.calculateTotalMetrics(normalizedAnalytics),
|
|
59
|
-
topPerformingPosts: this.getTopPerformingPosts(normalizedAnalytics),
|
|
60
|
-
engagementRate: this.calculateEngagementRate(normalizedAnalytics)
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// Update output parameters
|
|
64
|
-
const outputParams = [...Params];
|
|
65
|
-
const analyticsParam = outputParams.find(p => p.Name === 'Analytics');
|
|
66
|
-
if (analyticsParam) analyticsParam.Value = normalizedAnalytics;
|
|
67
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
68
|
-
if (summaryParam) summaryParam.Value = summary;
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
Success: true,
|
|
72
|
-
ResultCode: 'SUCCESS',
|
|
73
|
-
Message: 'Successfully retrieved analytics data',
|
|
74
|
-
Params: outputParams
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
} catch (error) {
|
|
78
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
Success: false,
|
|
82
|
-
ResultCode: 'ERROR',
|
|
83
|
-
Message: `Failed to get analytics: ${errorMessage}`,
|
|
84
|
-
Params
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Get analytics data from HootSuite
|
|
15
|
+
*/
|
|
16
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
17
|
+
const { Params, ContextUser } = params;
|
|
88
18
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
19
|
+
try {
|
|
20
|
+
// Initialize OAuth
|
|
21
|
+
const companyIntegrationId = this.getParamValue(Params, 'CompanyIntegrationID');
|
|
22
|
+
if (!(await this.initializeOAuth(companyIntegrationId))) {
|
|
23
|
+
throw new Error('Failed to initialize OAuth connection');
|
|
24
|
+
}
|
|
96
25
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
26
|
+
// Extract parameters
|
|
27
|
+
const postId = this.getParamValue(Params, 'PostID');
|
|
28
|
+
const profileId = this.getParamValue(Params, 'ProfileID');
|
|
29
|
+
const startDate = this.getParamValue(Params, 'StartDate');
|
|
30
|
+
const endDate = this.getParamValue(Params, 'EndDate');
|
|
31
|
+
const metricsType = this.getParamValue(Params, 'MetricsType') || 'all';
|
|
32
|
+
const aggregateByProfile = this.getParamValue(Params, 'AggregateByProfile') || false;
|
|
100
33
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
private async getProfileAnalytics(
|
|
105
|
-
profileId: string,
|
|
106
|
-
startDate?: string,
|
|
107
|
-
endDate?: string,
|
|
108
|
-
metricsType?: string
|
|
109
|
-
): Promise<any> {
|
|
110
|
-
const params: any = {
|
|
111
|
-
socialProfileIds: profileId
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
if (startDate) params.startTime = this.formatHootSuiteDate(startDate);
|
|
115
|
-
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
116
|
-
if (metricsType && metricsType !== 'all') params.metrics = this.getMetricsList(metricsType);
|
|
117
|
-
|
|
118
|
-
const response = await this.axiosInstance.get('/analytics/profiles', { params });
|
|
119
|
-
return response.data;
|
|
120
|
-
}
|
|
34
|
+
// Determine what analytics to fetch
|
|
35
|
+
let analyticsData: any;
|
|
121
36
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
endDate
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const profiles = await this.getSocialProfiles();
|
|
133
|
-
|
|
134
|
-
if (profiles.length === 0) {
|
|
135
|
-
return { data: [] };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const params: any = {
|
|
139
|
-
socialProfileIds: profiles.map(p => p.id).join(',')
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
if (startDate) params.startTime = this.formatHootSuiteDate(startDate);
|
|
143
|
-
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
144
|
-
if (metricsType && metricsType !== 'all') params.metrics = this.getMetricsList(metricsType);
|
|
145
|
-
if (aggregateByProfile) params.groupBy = 'socialProfile';
|
|
146
|
-
|
|
147
|
-
const response = await this.axiosInstance.get('/analytics/profiles', { params });
|
|
148
|
-
return response.data;
|
|
149
|
-
}
|
|
37
|
+
if (postId) {
|
|
38
|
+
// Get analytics for specific post
|
|
39
|
+
analyticsData = await this.getPostAnalytics(postId, startDate, endDate);
|
|
40
|
+
} else if (profileId) {
|
|
41
|
+
// Get analytics for specific profile
|
|
42
|
+
analyticsData = await this.getProfileAnalytics(profileId, startDate, endDate, metricsType);
|
|
43
|
+
} else {
|
|
44
|
+
// Get analytics for all profiles
|
|
45
|
+
analyticsData = await this.getAllProfilesAnalytics(startDate, endDate, metricsType, aggregateByProfile);
|
|
46
|
+
}
|
|
150
47
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*/
|
|
154
|
-
private getMetricsList(metricsType: string): string {
|
|
155
|
-
const metricsMap: Record<string, string[]> = {
|
|
156
|
-
'engagement': ['likes', 'comments', 'shares', 'engagements'],
|
|
157
|
-
'reach': ['impressions', 'reach'],
|
|
158
|
-
'clicks': ['clicks', 'linkClicks'],
|
|
159
|
-
'all': ['likes', 'comments', 'shares', 'clicks', 'impressions', 'engagements', 'reach']
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
return (metricsMap[metricsType] || metricsMap['all']).join(',');
|
|
163
|
-
}
|
|
48
|
+
// Normalize analytics
|
|
49
|
+
const normalizedAnalytics = this.processAnalyticsData(analyticsData, metricsType);
|
|
164
50
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
51
|
+
// Create summary
|
|
52
|
+
const summary = {
|
|
53
|
+
period: {
|
|
54
|
+
start: startDate || 'Not specified',
|
|
55
|
+
end: endDate || 'Not specified',
|
|
56
|
+
},
|
|
57
|
+
metricsType: metricsType,
|
|
58
|
+
totalMetrics: this.calculateTotalMetrics(normalizedAnalytics),
|
|
59
|
+
topPerformingPosts: this.getTopPerformingPosts(normalizedAnalytics),
|
|
60
|
+
engagementRate: this.calculateEngagementRate(normalizedAnalytics),
|
|
61
|
+
};
|
|
170
62
|
|
|
171
|
-
|
|
63
|
+
// Update output parameters
|
|
64
|
+
const outputParams = [...Params];
|
|
65
|
+
const analyticsParam = outputParams.find((p) => p.Name === 'Analytics');
|
|
66
|
+
if (analyticsParam) analyticsParam.Value = normalizedAnalytics;
|
|
67
|
+
const summaryParam = outputParams.find((p) => p.Name === 'Summary');
|
|
68
|
+
if (summaryParam) summaryParam.Value = summary;
|
|
172
69
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
70
|
+
return {
|
|
71
|
+
Success: true,
|
|
72
|
+
ResultCode: 'SUCCESS',
|
|
73
|
+
Message: 'Successfully retrieved analytics data',
|
|
74
|
+
Params: outputParams,
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
180
78
|
|
|
181
|
-
|
|
79
|
+
return {
|
|
80
|
+
Success: false,
|
|
81
|
+
ResultCode: 'ERROR',
|
|
82
|
+
Message: `Failed to get analytics: ${errorMessage}`,
|
|
83
|
+
Params,
|
|
84
|
+
};
|
|
182
85
|
}
|
|
86
|
+
}
|
|
183
87
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
clicks: total.clicks + current.clicks,
|
|
192
|
-
shares: total.shares + current.shares,
|
|
193
|
-
comments: total.comments + current.comments,
|
|
194
|
-
likes: total.likes + current.likes,
|
|
195
|
-
reach: total.reach + current.reach,
|
|
196
|
-
saves: (total.saves || 0) + (current.saves || 0),
|
|
197
|
-
videoViews: (total.videoViews || 0) + (current.videoViews || 0),
|
|
198
|
-
platformMetrics: {}
|
|
199
|
-
}), {
|
|
200
|
-
impressions: 0,
|
|
201
|
-
engagements: 0,
|
|
202
|
-
clicks: 0,
|
|
203
|
-
shares: 0,
|
|
204
|
-
comments: 0,
|
|
205
|
-
likes: 0,
|
|
206
|
-
reach: 0,
|
|
207
|
-
saves: 0,
|
|
208
|
-
videoViews: 0,
|
|
209
|
-
platformMetrics: {}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
88
|
+
/**
|
|
89
|
+
* Get analytics for a specific post
|
|
90
|
+
*/
|
|
91
|
+
private async getPostAnalytics(postId: string, startDate?: string, endDate?: string): Promise<HootSuiteAnalytics> {
|
|
92
|
+
const params: any = {};
|
|
93
|
+
if (startDate) params.startTime = this.formatHootSuiteDate(startDate);
|
|
94
|
+
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
212
95
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
private getTopPerformingPosts(analytics: SocialAnalytics[]): SocialAnalytics[] {
|
|
217
|
-
return analytics
|
|
218
|
-
.sort((a, b) => b.engagements - a.engagements)
|
|
219
|
-
.slice(0, 5);
|
|
220
|
-
}
|
|
96
|
+
const response = await this.axiosInstance.get(`/analytics/posts/${postId}`, { params });
|
|
97
|
+
return response.data;
|
|
98
|
+
}
|
|
221
99
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Get analytics for a specific profile
|
|
102
|
+
*/
|
|
103
|
+
private async getProfileAnalytics(profileId: string, startDate?: string, endDate?: string, metricsType?: string): Promise<any> {
|
|
104
|
+
const params: any = {
|
|
105
|
+
socialProfileIds: profileId,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (startDate) params.startTime = this.formatHootSuiteDate(startDate);
|
|
109
|
+
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
110
|
+
if (metricsType && metricsType !== 'all') params.metrics = this.getMetricsList(metricsType);
|
|
111
|
+
|
|
112
|
+
const response = await this.axiosInstance.get('/analytics/profiles', { params });
|
|
113
|
+
return response.data;
|
|
114
|
+
}
|
|
231
115
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
Value: null
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
Name: 'EndDate',
|
|
250
|
-
Type: 'Input',
|
|
251
|
-
Value: null
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
Name: 'MetricsType',
|
|
255
|
-
Type: 'Input',
|
|
256
|
-
Value: null
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
Name: 'AggregateByProfile',
|
|
260
|
-
Type: 'Input',
|
|
261
|
-
Value: null
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
Name: 'Analytics',
|
|
265
|
-
Type: 'Output',
|
|
266
|
-
Value: null
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
Name: 'Summary',
|
|
270
|
-
Type: 'Output',
|
|
271
|
-
Value: null
|
|
272
|
-
}
|
|
273
|
-
];
|
|
116
|
+
/**
|
|
117
|
+
* Get analytics for all profiles
|
|
118
|
+
*/
|
|
119
|
+
private async getAllProfilesAnalytics(
|
|
120
|
+
startDate?: string,
|
|
121
|
+
endDate?: string,
|
|
122
|
+
metricsType?: string,
|
|
123
|
+
aggregateByProfile?: boolean
|
|
124
|
+
): Promise<any> {
|
|
125
|
+
// First get all profiles
|
|
126
|
+
const profiles = await this.getSocialProfiles();
|
|
127
|
+
|
|
128
|
+
if (profiles.length === 0) {
|
|
129
|
+
return { data: [] };
|
|
274
130
|
}
|
|
275
131
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
132
|
+
const params: any = {
|
|
133
|
+
socialProfileIds: profiles.map((p) => p.id).join(','),
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
if (startDate) params.startTime = this.formatHootSuiteDate(startDate);
|
|
137
|
+
if (endDate) params.endTime = this.formatHootSuiteDate(endDate);
|
|
138
|
+
if (metricsType && metricsType !== 'all') params.metrics = this.getMetricsList(metricsType);
|
|
139
|
+
if (aggregateByProfile) params.groupBy = 'socialProfile';
|
|
140
|
+
|
|
141
|
+
const response = await this.axiosInstance.get('/analytics/profiles', { params });
|
|
142
|
+
return response.data;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get list of metrics based on type
|
|
147
|
+
*/
|
|
148
|
+
private getMetricsList(metricsType: string): string {
|
|
149
|
+
const metricsMap: Record<string, string[]> = {
|
|
150
|
+
engagement: ['likes', 'comments', 'shares', 'engagements'],
|
|
151
|
+
reach: ['impressions', 'reach'],
|
|
152
|
+
clicks: ['clicks', 'linkClicks'],
|
|
153
|
+
all: ['likes', 'comments', 'shares', 'clicks', 'impressions', 'engagements', 'reach'],
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return (metricsMap[metricsType] || metricsMap['all']).join(',');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Process and normalize analytics data
|
|
161
|
+
*/
|
|
162
|
+
private processAnalyticsData(data: any, metricsType: string): SocialAnalytics[] {
|
|
163
|
+
if (!data || !data.data) return [];
|
|
164
|
+
|
|
165
|
+
const results: SocialAnalytics[] = [];
|
|
166
|
+
|
|
167
|
+
if (Array.isArray(data.data)) {
|
|
168
|
+
data.data.forEach((item: any) => {
|
|
169
|
+
results.push(this.normalizeAnalytics(item.metrics));
|
|
170
|
+
});
|
|
171
|
+
} else if (data.metrics) {
|
|
172
|
+
results.push(this.normalizeAnalytics(data.metrics));
|
|
281
173
|
}
|
|
282
|
-
|
|
174
|
+
|
|
175
|
+
return results;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Calculate total metrics across all data
|
|
180
|
+
*/
|
|
181
|
+
private calculateTotalMetrics(analytics: SocialAnalytics[]): SocialAnalytics {
|
|
182
|
+
return analytics.reduce(
|
|
183
|
+
(total, current) => ({
|
|
184
|
+
impressions: total.impressions + current.impressions,
|
|
185
|
+
engagements: total.engagements + current.engagements,
|
|
186
|
+
clicks: total.clicks + current.clicks,
|
|
187
|
+
shares: total.shares + current.shares,
|
|
188
|
+
comments: total.comments + current.comments,
|
|
189
|
+
likes: total.likes + current.likes,
|
|
190
|
+
reach: total.reach + current.reach,
|
|
191
|
+
saves: (total.saves || 0) + (current.saves || 0),
|
|
192
|
+
videoViews: (total.videoViews || 0) + (current.videoViews || 0),
|
|
193
|
+
platformMetrics: {},
|
|
194
|
+
}),
|
|
195
|
+
{
|
|
196
|
+
impressions: 0,
|
|
197
|
+
engagements: 0,
|
|
198
|
+
clicks: 0,
|
|
199
|
+
shares: 0,
|
|
200
|
+
comments: 0,
|
|
201
|
+
likes: 0,
|
|
202
|
+
reach: 0,
|
|
203
|
+
saves: 0,
|
|
204
|
+
videoViews: 0,
|
|
205
|
+
platformMetrics: {},
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get top performing posts based on engagement
|
|
212
|
+
*/
|
|
213
|
+
private getTopPerformingPosts(analytics: SocialAnalytics[]): SocialAnalytics[] {
|
|
214
|
+
return analytics.sort((a, b) => b.engagements - a.engagements).slice(0, 5);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Calculate average engagement rate
|
|
219
|
+
*/
|
|
220
|
+
private calculateEngagementRate(analytics: SocialAnalytics[]): number {
|
|
221
|
+
const total = this.calculateTotalMetrics(analytics);
|
|
222
|
+
if (total.impressions === 0) return 0;
|
|
223
|
+
|
|
224
|
+
return (total.engagements / total.impressions) * 100;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Define the parameters this action expects
|
|
229
|
+
*/
|
|
230
|
+
public get Params(): ActionParam[] {
|
|
231
|
+
return [
|
|
232
|
+
...this.commonSocialParams,
|
|
233
|
+
{
|
|
234
|
+
Name: 'PostID',
|
|
235
|
+
Type: 'Input',
|
|
236
|
+
Value: null,
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
Name: 'StartDate',
|
|
240
|
+
Type: 'Input',
|
|
241
|
+
Value: null,
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
Name: 'EndDate',
|
|
245
|
+
Type: 'Input',
|
|
246
|
+
Value: null,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
Name: 'MetricsType',
|
|
250
|
+
Type: 'Input',
|
|
251
|
+
Value: null,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
Name: 'AggregateByProfile',
|
|
255
|
+
Type: 'Input',
|
|
256
|
+
Value: null,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
Name: 'Analytics',
|
|
260
|
+
Type: 'Output',
|
|
261
|
+
Value: null,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
Name: 'Summary',
|
|
265
|
+
Type: 'Output',
|
|
266
|
+
Value: null,
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Get action description
|
|
273
|
+
*/
|
|
274
|
+
public get Description(): string {
|
|
275
|
+
return 'Retrieves analytics data from HootSuite for posts, profiles, or overall account performance';
|
|
276
|
+
}
|
|
277
|
+
}
|