-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] youtube_analytics_api - new action components #15243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
components/youtube_analytics_api/actions/common/reports-query.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
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"; | ||
|
||
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", | ||
], | ||
}, | ||
endDate: { | ||
propDefinition: [ | ||
app, | ||
"endDate", | ||
], | ||
}, | ||
dimensions: { | ||
propDefinition: [ | ||
app, | ||
"dimensions", | ||
], | ||
}, | ||
sort: { | ||
propDefinition: [ | ||
app, | ||
"sort", | ||
], | ||
}, | ||
maxResults: { | ||
propDefinition: [ | ||
app, | ||
"maxResults", | ||
], | ||
}, | ||
}, | ||
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`.", | ||
}, | ||
}; | ||
} | ||
|
||
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).", | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
idType: propsFragments.idType, | ||
}; | ||
}, | ||
getIdsParam() { | ||
const { | ||
idType, | ||
ids, | ||
} = this; | ||
if (idType === constants.ID_TYPE.CHANNEL.value) { | ||
return "channel==MINE"; | ||
} | ||
if (idType === constants.ID_TYPE.CONTENT_OWNER.value) { | ||
return `contentOwner==${ids}`; | ||
} | ||
if (idType === constants.ID_TYPE.CHANNEL_ID.value) { | ||
return `channel==${ids}`; | ||
} | ||
}, | ||
getFiltersParam() { | ||
const { filters } = this; | ||
const filtersObj = utils.parseJson(filters); | ||
|
||
if (!filtersObj) { | ||
return; | ||
} | ||
|
||
return utils.arrayToCommaSeparatedList( | ||
Object.entries(filtersObj) | ||
.reduce((acc, [ | ||
key, | ||
val, | ||
]) => [ | ||
...acc, | ||
`${key}==${val}`, | ||
], []), | ||
";", | ||
); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}; |
54 changes: 54 additions & 0 deletions
54
components/youtube_analytics_api/actions/get-video-metrics/get-video-metrics.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import common from "../common/reports-query.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
import propsFragments from "../../common/props-fragments.mjs"; | ||
|
||
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", | ||
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`.", | ||
}, | ||
metrics: propsFragments.metrics, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
additionalProps() { | ||
return this.getIdsProps(); | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
videoId, | ||
getIdsParam, | ||
startDate, | ||
endDate, | ||
metrics, | ||
dimensions, | ||
sort, | ||
maxResults, | ||
} = this; | ||
|
||
const response = await app.reportsQuery({ | ||
$, | ||
params: { | ||
ids: getIdsParam(), | ||
startDate, | ||
endDate, | ||
metrics: utils.arrayToCommaSeparatedList(metrics), | ||
dimensions: utils.arrayToCommaSeparatedList(dimensions), | ||
sort: utils.arrayToCommaSeparatedList(sort), | ||
maxResults, | ||
filters: `video==${videoId}`, | ||
}, | ||
}); | ||
|
||
$.export("$summary", "Successfully fetched video metrics."); | ||
return response; | ||
}, | ||
}; |
106 changes: 106 additions & 0 deletions
106
components/youtube_analytics_api/actions/list-channel-reports/list-channel-reports.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import common from "../common/reports-query.mjs"; | ||
import constants from "../../common/constants.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
import propsFragments from "../../common/props-fragments.mjs"; | ||
|
||
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", | ||
type: "action", | ||
additionalProps() { | ||
const { | ||
getIdsProps, | ||
getReportTypeProps, | ||
} = this; | ||
|
||
return { | ||
...getIdsProps(), | ||
...getReportTypeProps(), | ||
}; | ||
}, | ||
methods: { | ||
...common.methods, | ||
getReportTypeProps() { | ||
const { channelReportType } = this; | ||
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]: "", | ||
}), {}); | ||
|
||
return { | ||
channelReportType: propsFragments.channelReportType, | ||
metrics: { | ||
...propsFragments.metrics, | ||
options: VIDEO_BASIC_USER_ACTIVITY_STATS.metadata.metrics, | ||
}, | ||
filters: { | ||
...propsFragments.filters, | ||
description: `**Supported filters: \`${JSON.stringify(supportedFilters)}\`**. ${propsFragments.filters.description}`, | ||
}, | ||
}; | ||
} | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (channelReportType === PLAYLIST_BASIC_STATS.value) { | ||
const supportedFilters = PLAYLIST_BASIC_STATS.metadata.filters | ||
.reduce((acc, filter) => ({ | ||
...acc, | ||
[filter]: "", | ||
}), {}); | ||
|
||
return { | ||
channelReportType: propsFragments.channelReportType, | ||
metrics: { | ||
...propsFragments.metrics, | ||
options: PLAYLIST_BASIC_STATS.metadata.metrics, | ||
}, | ||
filters: { | ||
...propsFragments.filters, | ||
description: `**Supported filters: \`${JSON.stringify(supportedFilters)}\`**. ${propsFragments.filters.description}`, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
channelReportType: propsFragments.channelReportType, | ||
}; | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
getIdsParam, | ||
getFiltersParam, | ||
startDate, | ||
endDate, | ||
metrics, | ||
sort, | ||
maxResults, | ||
} = this; | ||
|
||
const response = await app.reportsQuery({ | ||
$, | ||
params: { | ||
ids: getIdsParam(), | ||
startDate, | ||
endDate, | ||
metrics: utils.arrayToCommaSeparatedList(metrics), | ||
filters: getFiltersParam(), | ||
sort: utils.arrayToCommaSeparatedList(sort), | ||
maxResults, | ||
}, | ||
}); | ||
|
||
$.export("$summary", "Successfully fetched channel reports."); | ||
return response; | ||
}, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
50 changes: 50 additions & 0 deletions
50
components/youtube_analytics_api/actions/query-custom-analytics/query-custom-analytics.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import common from "../common/reports-query.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
import propsFragments from "../../common/props-fragments.mjs"; | ||
|
||
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", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
metrics: propsFragments.metrics, | ||
filters: propsFragments.filters, | ||
}, | ||
additionalProps() { | ||
return this.getIdsProps(); | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
getIdsParam, | ||
getFiltersParam, | ||
startDate, | ||
endDate, | ||
metrics, | ||
dimensions, | ||
sort, | ||
maxResults, | ||
} = this; | ||
|
||
const response = await app.reportsQuery({ | ||
$, | ||
params: { | ||
ids: getIdsParam(), | ||
startDate, | ||
endDate, | ||
metrics: utils.arrayToCommaSeparatedList(metrics), | ||
dimensions: utils.arrayToCommaSeparatedList(dimensions), | ||
filters: getFiltersParam(), | ||
sort: utils.arrayToCommaSeparatedList(sort), | ||
maxResults, | ||
}, | ||
}); | ||
|
||
$.export("$summary", "Successfully fetched custom analytics data."); | ||
return response; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮 Cool use of the
reloader
prop! I didn't know that would work.