-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[ACTION] PostHog - Insights API #19346
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
Open
jcortes
wants to merge
1
commit into
master
Choose a base branch
from
posthog-new-components
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+505
−7
Open
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
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
108 changes: 108 additions & 0 deletions
108
components/posthog/actions/create-project-insight/create-project-insight.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,108 @@ | ||
| import posthog from "../../posthog.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "posthog-create-project-insight", | ||
| name: "Create Project Insight", | ||
| description: "Create a new insight in a project. [See the documentation](https://posthog.com/docs/api/insights#post-api-projects-project_id-insights)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| idempotentHint: false, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| posthog, | ||
| organizationId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "organizationId", | ||
| ], | ||
| }, | ||
| projectId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "projectId", | ||
| (c) => ({ | ||
| organizationId: c.organizationId, | ||
| }), | ||
| ], | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Name of the insight", | ||
| optional: true, | ||
| }, | ||
| derivedName: { | ||
| type: "string", | ||
| label: "Derived Name", | ||
| description: "Derived name of the insight", | ||
| optional: true, | ||
| }, | ||
| query: { | ||
| type: "object", | ||
| label: "Query", | ||
| description: "Query object defining the insight. Must be a valid PostHog query object (e.g., InsightVizNode with source)", | ||
| optional: true, | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| description: "Description of the insight", | ||
| optional: true, | ||
| }, | ||
| tags: { | ||
| type: "string[]", | ||
| label: "Tags", | ||
| description: "Tags for the insight", | ||
| optional: true, | ||
| }, | ||
| favorited: { | ||
| type: "boolean", | ||
| label: "Favorited", | ||
| description: "Whether the insight is favorited", | ||
| optional: true, | ||
| }, | ||
| deleted: { | ||
| type: "boolean", | ||
| label: "Deleted", | ||
| description: "Whether the insight is deleted", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| posthog, | ||
| projectId, | ||
| name, | ||
| derivedName, | ||
| query, | ||
| description, | ||
| tags, | ||
| favorited, | ||
| deleted, | ||
| } = this; | ||
|
|
||
| const insight = await posthog.createInsight({ | ||
| $, | ||
| projectId, | ||
| data: { | ||
| name, | ||
| derived_name: derivedName, | ||
| query: utils.parseJson(query), | ||
| description, | ||
| tags: utils.parseJson(tags), | ||
| favorited, | ||
| deleted, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully created insight${name | ||
| ? ` "${name}"` | ||
| : ""} with ID ${insight.id}`); | ||
| return insight; | ||
| }, | ||
| }; |
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
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
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
85 changes: 85 additions & 0 deletions
85
components/posthog/actions/get-project-insight/get-project-insight.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,85 @@ | ||
| import posthog from "../../posthog.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "posthog-get-project-insight", | ||
| name: "Get Project Insight", | ||
| description: "Retrieve a specific insight from a project. [See the documentation](https://posthog.com/docs/api/insights#get-api-projects-project_id-insights-id)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| idempotentHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| posthog, | ||
| organizationId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "organizationId", | ||
| ], | ||
| }, | ||
| projectId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "projectId", | ||
| (c) => ({ | ||
| organizationId: c.organizationId, | ||
| }), | ||
| ], | ||
| }, | ||
| insightId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "insightId", | ||
| (c) => ({ | ||
| projectId: c.projectId, | ||
| }), | ||
| ], | ||
| }, | ||
| fromDashboard: { | ||
| type: "string", | ||
| label: "From Dashboard", | ||
| description: "Only if loading an insight in the context of a dashboard: The relevant dashboard's ID. When set, the specified dashboard's filters and date range override will be applied.", | ||
| optional: true, | ||
| }, | ||
| refresh: { | ||
| type: "string", | ||
| label: "Refresh", | ||
| description: "Whether to refresh the insight. Options: `force_cache`, `blocking`, `async`, `lazy_async`, `force_blocking`, `force_async`", | ||
| optional: true, | ||
| default: "force_cache", | ||
| options: [ | ||
| "force_cache", | ||
| "blocking", | ||
| "async", | ||
| "lazy_async", | ||
| "force_blocking", | ||
| "force_async", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| posthog, | ||
| projectId, | ||
| insightId, | ||
| fromDashboard, | ||
| refresh, | ||
| } = this; | ||
|
|
||
| const insight = await posthog.getInsight({ | ||
| $, | ||
| projectId, | ||
| insightId, | ||
| params: { | ||
| from_dashboard: fromDashboard, | ||
| refresh, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully retrieved insight with ID ${insightId}`); | ||
| return insight; | ||
| }, | ||
| }; | ||
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
87 changes: 87 additions & 0 deletions
87
components/posthog/actions/list-project-insights/list-project-insights.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,87 @@ | ||
| import posthog from "../../posthog.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "posthog-list-project-insights", | ||
| name: "List Project Insights", | ||
| description: "Retrieve a list of insights for a project. [See the documentation](https://posthog.com/docs/api/insights#get-api-projects-project_id-insights)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| idempotentHint: true, | ||
| }, | ||
| type: "action", | ||
| props: { | ||
| posthog, | ||
| organizationId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "organizationId", | ||
| ], | ||
| }, | ||
| projectId: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "projectId", | ||
| (c) => ({ | ||
| organizationId: c.organizationId, | ||
| }), | ||
| ], | ||
| }, | ||
| basic: { | ||
| type: "boolean", | ||
| label: "Basic", | ||
| description: "Return basic insight metadata only (no results, faster).", | ||
| optional: true, | ||
| }, | ||
| refresh: { | ||
| type: "string", | ||
| label: "Refresh", | ||
| description: "Whether to refresh the retrieved insights. Options: `force_cache`, `blocking`, `async`, `lazy_async`, `force_blocking`, `force_async`. Default: `force_cache`", | ||
| optional: true, | ||
| default: "force_cache", | ||
| options: [ | ||
| "force_cache", | ||
| "blocking", | ||
| "async", | ||
| "lazy_async", | ||
| "force_blocking", | ||
| "force_async", | ||
| ], | ||
|
Comment on lines
+44
to
+51
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to a |
||
| }, | ||
| maxResults: { | ||
| propDefinition: [ | ||
| posthog, | ||
| "maxResults", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| posthog, | ||
| projectId, | ||
| basic, | ||
| refresh, | ||
| maxResults, | ||
| } = this; | ||
|
|
||
| const insights = await posthog.iterateResults({ | ||
| fn: posthog.listInsights, | ||
| args: { | ||
| $, | ||
| projectId, | ||
| params: { | ||
| basic, | ||
| refresh, | ||
| }, | ||
| }, | ||
| max: maxResults, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully retrieved ${insights.length} insight${insights.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| return insights; | ||
| }, | ||
| }; | ||
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.