Skip to content

Commit 6e4800c

Browse files
committed
Merge remote-tracking branch 'origin/master' into docs-theme-config-fix
2 parents 1c51198 + b6765b4 commit 6e4800c

File tree

10 files changed

+668
-6
lines changed

10 files changed

+668
-6
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import app from "../../youtube_analytics_api.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
import propsFragments from "../../common/props-fragments.mjs";
5+
6+
export default {
7+
props: {
8+
app,
9+
reloader: {
10+
type: "boolean",
11+
label: "Hidden Reloader",
12+
description: "This prop is used to reload the props when the step gets created.",
13+
hidden: true,
14+
reloadProps: true,
15+
},
16+
startDate: {
17+
propDefinition: [
18+
app,
19+
"startDate",
20+
],
21+
},
22+
endDate: {
23+
propDefinition: [
24+
app,
25+
"endDate",
26+
],
27+
},
28+
dimensions: {
29+
propDefinition: [
30+
app,
31+
"dimensions",
32+
],
33+
},
34+
sort: {
35+
propDefinition: [
36+
app,
37+
"sort",
38+
],
39+
},
40+
maxResults: {
41+
propDefinition: [
42+
app,
43+
"maxResults",
44+
],
45+
},
46+
},
47+
methods: {
48+
getIdsProps() {
49+
const { idType } = this;
50+
51+
if (idType === constants.ID_TYPE.CHANNEL.value) {
52+
return {
53+
idType: propsFragments.idType,
54+
};
55+
}
56+
57+
if (idType === constants.ID_TYPE.CONTENT_OWNER.value) {
58+
return {
59+
idType: propsFragments.idType,
60+
ids: {
61+
type: "string",
62+
label: "Content Owner Name",
63+
description: "The content owner name for the user. Eg. `MyContentOwnerName`.",
64+
},
65+
};
66+
}
67+
68+
if (idType === constants.ID_TYPE.CHANNEL_ID.value) {
69+
return {
70+
idType: propsFragments.idType,
71+
ids: {
72+
type: "string",
73+
label: "Channel ID",
74+
description: "The channel ID for the user. Eg. `UC_x5XG1OV2P6uZZ5FSM9Ttw`. You can find the ID using the [YouTube Data API](https://developers.google.com/youtube/v3/docs/channels/list).",
75+
},
76+
};
77+
}
78+
79+
return {
80+
idType: propsFragments.idType,
81+
};
82+
},
83+
getIdsParam() {
84+
const {
85+
idType,
86+
ids,
87+
} = this;
88+
if (idType === constants.ID_TYPE.CHANNEL.value) {
89+
return "channel==MINE";
90+
}
91+
if (idType === constants.ID_TYPE.CONTENT_OWNER.value) {
92+
return `contentOwner==${ids}`;
93+
}
94+
if (idType === constants.ID_TYPE.CHANNEL_ID.value) {
95+
return `channel==${ids}`;
96+
}
97+
},
98+
getFiltersParam() {
99+
const { filters } = this;
100+
const filtersObj = utils.parseJson(filters);
101+
102+
if (!filtersObj) {
103+
return;
104+
}
105+
106+
return utils.arrayToCommaSeparatedList(
107+
Object.entries(filtersObj)
108+
.reduce((acc, [
109+
key,
110+
val,
111+
]) => [
112+
...acc,
113+
`${key}==${val}`,
114+
], []),
115+
";",
116+
);
117+
},
118+
},
119+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import common from "../common/reports-query.mjs";
2+
import utils from "../../common/utils.mjs";
3+
import propsFragments from "../../common/props-fragments.mjs";
4+
5+
export default {
6+
...common,
7+
key: "youtube_analytics_api-get-video-metrics",
8+
name: "Get Video Metrics",
9+
description: "Retrieve detailed analytics for a specific video. [See the documentation](https://developers.google.com/youtube/analytics/reference/reports/query)",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
...common.props,
14+
videoId: {
15+
type: "string",
16+
label: "Video ID",
17+
description: "The ID of the video for which you want to retrieve metrics. Eg. `pd1FJh59zxQ`.",
18+
},
19+
metrics: propsFragments.metrics,
20+
},
21+
additionalProps() {
22+
return this.getIdsProps();
23+
},
24+
async run({ $ }) {
25+
const {
26+
app,
27+
videoId,
28+
getIdsParam,
29+
startDate,
30+
endDate,
31+
metrics,
32+
dimensions,
33+
sort,
34+
maxResults,
35+
} = this;
36+
37+
const response = await app.reportsQuery({
38+
$,
39+
params: {
40+
ids: getIdsParam(),
41+
startDate,
42+
endDate,
43+
metrics: utils.arrayToCommaSeparatedList(metrics),
44+
dimensions: utils.arrayToCommaSeparatedList(dimensions),
45+
sort: utils.arrayToCommaSeparatedList(sort),
46+
maxResults,
47+
filters: `video==${videoId}`,
48+
},
49+
});
50+
51+
$.export("$summary", "Successfully fetched video metrics.");
52+
return response;
53+
},
54+
};
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import common from "../common/reports-query.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
import propsFragments from "../../common/props-fragments.mjs";
5+
6+
export default {
7+
...common,
8+
key: "youtube_analytics_api-list-channel-reports",
9+
name: "List Channel Reports",
10+
description: "Fetch summary analytics reports for a specified youtube channel. Optional filters include date range and report type. [See the documentation](https://developers.google.com/youtube/analytics/reference/reports/query)",
11+
version: "0.0.1",
12+
type: "action",
13+
additionalProps() {
14+
const {
15+
getIdsProps,
16+
getReportTypeProps,
17+
} = this;
18+
19+
return {
20+
...getIdsProps(),
21+
...getReportTypeProps(),
22+
};
23+
},
24+
methods: {
25+
...common.methods,
26+
getReportTypeProps() {
27+
const { channelReportType } = this;
28+
const {
29+
VIDEO_BASIC_USER_ACTIVITY_STATS,
30+
PLAYLIST_BASIC_STATS,
31+
} = constants.CHANNEL_REPORT_TYPE;
32+
33+
if (channelReportType === VIDEO_BASIC_USER_ACTIVITY_STATS.value) {
34+
const supportedFilters = VIDEO_BASIC_USER_ACTIVITY_STATS.metadata.filters
35+
.reduce((acc, filter) => ({
36+
...acc,
37+
[filter]: "",
38+
}), {});
39+
40+
return {
41+
channelReportType: propsFragments.channelReportType,
42+
metrics: {
43+
...propsFragments.metrics,
44+
options: VIDEO_BASIC_USER_ACTIVITY_STATS.metadata.metrics,
45+
},
46+
filters: {
47+
...propsFragments.filters,
48+
description: `**Supported filters: \`${JSON.stringify(supportedFilters)}\`**. ${propsFragments.filters.description}`,
49+
},
50+
};
51+
}
52+
53+
if (channelReportType === PLAYLIST_BASIC_STATS.value) {
54+
const supportedFilters = PLAYLIST_BASIC_STATS.metadata.filters
55+
.reduce((acc, filter) => ({
56+
...acc,
57+
[filter]: "",
58+
}), {});
59+
60+
return {
61+
channelReportType: propsFragments.channelReportType,
62+
metrics: {
63+
...propsFragments.metrics,
64+
options: PLAYLIST_BASIC_STATS.metadata.metrics,
65+
},
66+
filters: {
67+
...propsFragments.filters,
68+
description: `**Supported filters: \`${JSON.stringify(supportedFilters)}\`**. ${propsFragments.filters.description}`,
69+
},
70+
};
71+
}
72+
73+
return {
74+
channelReportType: propsFragments.channelReportType,
75+
};
76+
},
77+
},
78+
async run({ $ }) {
79+
const {
80+
app,
81+
getIdsParam,
82+
getFiltersParam,
83+
startDate,
84+
endDate,
85+
metrics,
86+
sort,
87+
maxResults,
88+
} = this;
89+
90+
const response = await app.reportsQuery({
91+
$,
92+
params: {
93+
ids: getIdsParam(),
94+
startDate,
95+
endDate,
96+
metrics: utils.arrayToCommaSeparatedList(metrics),
97+
filters: getFiltersParam(),
98+
sort: utils.arrayToCommaSeparatedList(sort),
99+
maxResults,
100+
},
101+
});
102+
103+
$.export("$summary", "Successfully fetched channel reports.");
104+
return response;
105+
},
106+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import common from "../common/reports-query.mjs";
2+
import utils from "../../common/utils.mjs";
3+
import propsFragments from "../../common/props-fragments.mjs";
4+
5+
export default {
6+
...common,
7+
key: "youtube_analytics_api-query-custom-analytics",
8+
name: "Query Custom Analytics",
9+
description: "Execute a custom analytics query using specified metrics, dimensions, filters, and date ranges. Requires query parameters to configure. [See the documentation](https://developers.google.com/youtube/analytics/reference/reports/query).",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
...common.props,
14+
metrics: propsFragments.metrics,
15+
filters: propsFragments.filters,
16+
},
17+
additionalProps() {
18+
return this.getIdsProps();
19+
},
20+
async run({ $ }) {
21+
const {
22+
app,
23+
getIdsParam,
24+
getFiltersParam,
25+
startDate,
26+
endDate,
27+
metrics,
28+
dimensions,
29+
sort,
30+
maxResults,
31+
} = this;
32+
33+
const response = await app.reportsQuery({
34+
$,
35+
params: {
36+
ids: getIdsParam(),
37+
startDate,
38+
endDate,
39+
metrics: utils.arrayToCommaSeparatedList(metrics),
40+
dimensions: utils.arrayToCommaSeparatedList(dimensions),
41+
filters: getFiltersParam(),
42+
sort: utils.arrayToCommaSeparatedList(sort),
43+
maxResults,
44+
},
45+
});
46+
47+
$.export("$summary", "Successfully fetched custom analytics data.");
48+
return response;
49+
},
50+
};

0 commit comments

Comments
 (0)