Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 24 additions & 52 deletions components/youtube_analytics_api/actions/common/reports-query.mjs
Original file line number Diff line number Diff line change
@@ -1,90 +1,66 @@
import app from "../../youtube_analytics_api.app.mjs";
import constants from "../../common/constants.mjs";
import utils from "../../common/utils.mjs";
import propsFragments from "../../common/props-fragments.mjs";

Check failure on line 4 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'propsFragments' is defined but never used

export default {
props: {
app,
reloader: {
type: "boolean",
label: "Hidden Reloader",
description: "This prop is used to reload the props when the step gets created.",
hidden: true,
reloadProps: true,
},
startDate: {
propDefinition: [
app,
"startDate",
],
propDefinition: [app, "startDate"],

Check failure on line 10 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required after '['

Check failure on line 10 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

There should be a linebreak after this element

Check failure on line 10 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required before ']'
},
endDate: {
propDefinition: [
app,
"endDate",
],
propDefinition: [app, "endDate"],

Check failure on line 13 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required after '['

Check failure on line 13 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

There should be a linebreak after this element

Check failure on line 13 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required before ']'
},
dimensions: {
propDefinition: [
app,
"dimensions",
],
propDefinition: [app, "dimensions"],

Check failure on line 16 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required after '['

Check failure on line 16 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

There should be a linebreak after this element

Check failure on line 16 in components/youtube_analytics_api/actions/common/reports-query.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required before ']'
},
sort: {
propDefinition: [
app,
"sort",
],
propDefinition: [app, "sort"],
},
maxResults: {
propDefinition: [
app,
"maxResults",
],
propDefinition: [app, "maxResults"],
},
idType: {
type: "string",
label: "ID Type",
description:
"The type of ID to use for the query. This can be either `My Channel`, `Channel ID`, or `Content Owner`.",
options: Object.values(constants.ID_TYPE),
default: constants.ID_TYPE.CHANNEL.value,
reloadProps: true,
},
},
methods: {
getIdsProps() {
const { idType } = this;

if (idType === constants.ID_TYPE.CHANNEL.value) {
return {
idType: propsFragments.idType,
};
}

if (idType === constants.ID_TYPE.CONTENT_OWNER.value) {
return {
idType: propsFragments.idType,
ids: {
type: "string",
label: "Content Owner Name",
description: "The content owner name for the user. Eg. `MyContentOwnerName`.",
description:
"The content owner name for the user. Eg. `MyContentOwnerName`.",
},
};
}

if (idType === constants.ID_TYPE.CHANNEL_ID.value) {
return {
idType: propsFragments.idType,
ids: {
type: "string",
label: "Channel ID",
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).",
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).",
},
};
}

return {
idType: propsFragments.idType,
};
return {};
},
getIdsParam() {
const {
idType,
ids,
} = this;
const { idType, ids } = this;
if (idType === constants.ID_TYPE.CHANNEL.value) {
return "channel==MINE";
}
Expand All @@ -104,14 +80,10 @@
}

return utils.arrayToCommaSeparatedList(
Object.entries(filtersObj)
.reduce((acc, [
key,
val,
]) => [
...acc,
`${key}==${val}`,
], []),
Object.entries(filtersObj).reduce(
(acc, [key, val]) => [...acc, `${key}==${val}`],
[],
),
";",
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ export default {
...common,
key: "youtube_analytics_api-get-video-metrics",
name: "Get Video Metrics",
description: "Retrieve detailed analytics for a specific video. [See the documentation](https://developers.google.com/youtube/analytics/reference/reports/query)",
version: "0.0.1",
description:
"Retrieve detailed analytics for a specific video. [See the documentation](https://developers.google.com/youtube/analytics/reference/reports/query)",
version: "0.0.2",
type: "action",
props: {
...common.props,
videoId: {
type: "string",
label: "Video ID",
description: "The ID of the video for which you want to retrieve metrics. Eg. `pd1FJh59zxQ`.",
description:
"The ID of the video for which you want to retrieve metrics. Eg. `pd1FJh59zxQ`.",
},
metrics: propsFragments.metrics,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ export default {
...common,
key: "youtube_analytics_api-list-channel-reports",
name: "List Channel Reports",
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)",
version: "0.0.1",
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)",
version: "0.0.2",
type: "action",
additionalProps() {
const {
getIdsProps,
getReportTypeProps,
} = this;
const { getIdsProps, getReportTypeProps } = this;

return {
...getIdsProps(),
Expand All @@ -25,17 +23,18 @@ export default {
...common.methods,
getReportTypeProps() {
const { channelReportType } = this;
const {
VIDEO_BASIC_USER_ACTIVITY_STATS,
PLAYLIST_BASIC_STATS,
} = constants.CHANNEL_REPORT_TYPE;
const { VIDEO_BASIC_USER_ACTIVITY_STATS, PLAYLIST_BASIC_STATS } =
constants.CHANNEL_REPORT_TYPE;

if (channelReportType === VIDEO_BASIC_USER_ACTIVITY_STATS.value) {
const supportedFilters = VIDEO_BASIC_USER_ACTIVITY_STATS.metadata.filters
.reduce((acc, filter) => ({
...acc,
[filter]: "",
}), {});
const supportedFilters =
VIDEO_BASIC_USER_ACTIVITY_STATS.metadata.filters.reduce(
(acc, filter) => ({
...acc,
[filter]: "",
}),
{},
);

return {
channelReportType: propsFragments.channelReportType,
Expand All @@ -51,11 +50,13 @@ export default {
}

if (channelReportType === PLAYLIST_BASIC_STATS.value) {
const supportedFilters = PLAYLIST_BASIC_STATS.metadata.filters
.reduce((acc, filter) => ({
const supportedFilters = PLAYLIST_BASIC_STATS.metadata.filters.reduce(
(acc, filter) => ({
...acc,
[filter]: "",
}), {});
}),
{},
);

return {
channelReportType: propsFragments.channelReportType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export default {
...common,
key: "youtube_analytics_api-query-custom-analytics",
name: "Query Custom Analytics",
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).",
version: "0.0.1",
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).",
version: "0.0.2",
type: "action",
props: {
...common.props,
Expand Down
27 changes: 12 additions & 15 deletions components/youtube_analytics_api/common/props-fragments.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
import constants from "./constants.mjs";

export default {
idType: {
type: "string",
label: "ID Type",
description: "The type of ID to use for the query. This can be either `My Channel`, `Channel ID`, or `Content Owner`.",
options: Object.values(constants.ID_TYPE),
default: constants.ID_TYPE.CHANNEL.value,
reloadProps: true,
},
channelReportType: {
type: "string",
label: "Channel Report Type",
description: "The type of report to fetch for the specified YouTube Channel. This selects default dimensions, metrics and filters.",
options: Object.values(constants.CHANNEL_REPORT_TYPE)
.map(({
description:
"The type of report to fetch for the specified YouTube Channel. This selects default dimensions, metrics and filters.",
options: Object.values(constants.CHANNEL_REPORT_TYPE).map(
({
// eslint-disable-next-line no-unused-vars
metadata,
...rest
}) => rest),
default: constants.CHANNEL_REPORT_TYPE.VIDEO_BASIC_USER_ACTIVITY_STATS.value,
}) => rest,
),
default:
constants.CHANNEL_REPORT_TYPE.VIDEO_BASIC_USER_ACTIVITY_STATS.value,
reloadProps: true,
},
metrics: {
type: "string[]",
label: "Metrics",
description: "Metrics, such as `views` or `likes`, `dislikes`. See the documentation for [channel reports](https://developers.google.com/youtube/analytics/channel_reports) or [content owner reports](https://developers.google.com/youtube/analytics/content_owner_reports) for a list of the reports that you can retrieve and the metrics available in each report. (The [Metrics](https://developers.google.com/youtube/reporting#metrics) document contains definitions for all of the metrics.).",
description:
"Metrics, such as `views` or `likes`, `dislikes`. See the documentation for [channel reports](https://developers.google.com/youtube/analytics/channel_reports) or [content owner reports](https://developers.google.com/youtube/analytics/content_owner_reports) for a list of the reports that you can retrieve and the metrics available in each report. (The [Metrics](https://developers.google.com/youtube/reporting#metrics) document contains definitions for all of the metrics.).",
options: Object.values(constants.METRIC),
},
filters: {
type: "object",
label: "Filters",
description: "A list of filters that should be applied when retrieving YouTube Analytics data. The documentation for [channel reports](https://developers.google.com/youtube/analytics/channel_reports) and [content owner reports](https://developers.google.com/youtube/analytics/content_owner_reports) identifies the dimensions that can be used to filter each report, and the [Dimensions](https://developers.google.com/youtube/analytics/dimsmets/dims) document defines those dimensions.\n\nIf a request uses multiple filters the returned result table will satisfy both filters. For example, a filters parameter value of `{\"video\":\"dMH0bHeiRNg\",\"country\":\"IT\"}` restricts the result set to include data for the given video in Italy.\n\nSpecifying multiple values for a filter\nThe API supports the ability to specify multiple values for the [video](https://developers.google.com/youtube/reporting#supported-reports), [playlist](https://developers.google.com/youtube/reporting#supported-reports), and [channel](https://developers.google.com/youtube/reporting#supported-reports) filters. To do so, specify a separated list of the video, playlist, or channel IDs for which the API response should be filtered. For example, a filters parameter value of `{\"video\":\"pd1FJh59zxQ,Zhawgd0REhA\",\"country\":\"IT\"}` restricts the result set to include data for the given videos in Italy. The parameter value can specify up to 500 IDs. For more details on the filters parameter, see the filters parameter in [Parameters](https://developers.google.com/youtube/analytics/reference/reports/query#Parameters) section.",
description:
'A list of filters that should be applied when retrieving YouTube Analytics data. The documentation for [channel reports](https://developers.google.com/youtube/analytics/channel_reports) and [content owner reports](https://developers.google.com/youtube/analytics/content_owner_reports) identifies the dimensions that can be used to filter each report, and the [Dimensions](https://developers.google.com/youtube/analytics/dimsmets/dims) document defines those dimensions.\n\nIf a request uses multiple filters the returned result table will satisfy both filters. For example, a filters parameter value of `{"video":"dMH0bHeiRNg","country":"IT"}` restricts the result set to include data for the given video in Italy.\n\nSpecifying multiple values for a filter\nThe API supports the ability to specify multiple values for the [video](https://developers.google.com/youtube/reporting#supported-reports), [playlist](https://developers.google.com/youtube/reporting#supported-reports), and [channel](https://developers.google.com/youtube/reporting#supported-reports) filters. To do so, specify a separated list of the video, playlist, or channel IDs for which the API response should be filtered. For example, a filters parameter value of `{"video":"pd1FJh59zxQ,Zhawgd0REhA","country":"IT"}` restricts the result set to include data for the given videos in Italy. The parameter value can specify up to 500 IDs. For more details on the filters parameter, see the filters parameter in [Parameters](https://developers.google.com/youtube/analytics/reference/reports/query#Parameters) section.',
optional: true,
},
};
Loading