PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
19.61k stars 1.15k forks source link

Ability to run analytics on array data #11095

Open lsmith77 opened 1 year ago

lsmith77 commented 1 year ago

Is your feature request related to a problem?

Take the below example, we want to run analytics on the response.results array, like finding the categories that are matched the most often etc.

{
    "id": "01825f63-99e6-0000-8dff-b218400aa051",
    "timestamp": "2022-08-02T16:28:59.186000+00:00",
    "event": "check",
    "distinct_id": "DEV_APP_ID",
    "properties": {
        "$browser": "Chrome",
        "$browser_version": 104,
        "$device": "",
        "$geoip_continent_code": "EU",
        "$geoip_continent_name": "Europe",
        "$geoip_country_code": "CH",
        "$geoip_country_name": "Switzerland",
        "$geoip_subdivision_1_code": "ZH",
        "$geoip_subdivision_1_name": "Zurich",
        "$geoip_time_zone": "Europe/Zurich",
        "$host": "www.witty.works",
        "$insert_id": "lswfh4o4cgnhd3ja",
        "$lib": "js",
        "$lib_version": "0.0.5",
        "$os": "Linux",
        "$pathname": "/editor",
        "$referring_domain": "",
        "$screen_dpr": 1,
        "$screen_height": 720,
        "$screen_width": 1280,
        "$set_once": {
            "$initial_os": "Linux",
            "$initial_browser": "Chrome",
            "$initial_referrer": "",
            "$initial_referring_domain": "",
            "$initial_current_url": "https://www.witty.works/editor",
            "$initial_pathname": "/editor",
            "$initial_browser_version": 104
        },
        "$time": 1659457738.987,
        "request__client": "1.23.0.1",
        "request__config__german_gender_ending": "*in",
        "request__config__preferred_variants": [
            "de-DE",
            "en-US"
        ],
        "request__id": "DEV_APP_ID",
        "request__lang": "auto",
        "request__text__length": 532,
        "request__type": "check",
        "response": {
            "results": [
                {
                    "text": "mistacke",
                    "context": "Witty corrects grammar and spelling mistakes. They are highlighted in red:\n\nThis is a spelling mistacke. \n  \n\n\nWait... there is more. Witty highlights style issues in yellow:\n    \nThis is actually a very",
                    "category": "orthography",
                    "subcategory": "typos",
                    "start": 410,
                    "end": 418,
                    "alternatives": [
                        {
                            "text": "mistake"
                        }
                    ],
                    "label": "Spelling mistake",
                    "explanation": {
                        "text": "Possible spelling mistake found.",
                        "icon": "❌"
                    },
                    "gravity": 1
                },
                {
                    "text": "front-end developer",
                    "context": "y highlights biased and gendered language in orange: \n   \nHey guys, we're excited to announce a new front-end developer will assume the leadership role. Taylor has extensive expertise and a strong technical background.",
                    "category": "gendered",
                    "subcategory": "titles",
                    "start": 116,
                    "end": 135,
                    "alternatives": [
                        {
                            "text": "front-end development"
                        },
                        {
                            "text": "they"
                        },
                        {
                            "text": "colleague in front-end development"
                        },
                        {
                            "text": "front-end development team"
                        },
                        {
                            "text": "front-end developers"
                        },
                        {
                            "text": "colleagues in front-end development"
                        }
                    ],
                    "label": "Gendered: Titles",
                    "explanation": {
                        "text": "Male generic doesn’t address all genders",
                        "icon": "😟",
                        "url": "https://www.witty.works/en/categories/gendered#titles"
                    },
                    "gravity": 2
                },
                {
                    "text": "guys",
                    "context": "The basics: Witty highlights biased and gendered language in orange: \n   \nHey guys, we're excited to announce a new front-end developer will assume the leadership role. Taylor has ex",
                    "category": "gendered",
                    "subcategory": "function",
                    "start": 78,
                    "end": 82,
                    "alternatives": [
                        {
                            "text": "people"
                        },
                        {
                            "text": "folks"
                        },
                        {
                            "text": "friends"
                        },
                        {
                            "text": "all"
                        },
                        {
                            "text": "you all"
                        },
                        {
                            "text": "everyone"
                        },
                        {
                            "text": "teammates"
                        },
                        {
                            "text": "you"
                        },
                        {
                            "text": "team"
                        },
                        {
                            "text": "crowd"
                        }
                    ],
                    "label": "Gendered: Special functions",
                    "explanation": {
                        "text": "Image of a man unconsciously triggered",
                        "icon": "💡",
                        "url": "https://www.witty.works/en/categories/gendered#special_functions"
                    },
                    "gravity": 2
                },
                {
                    "text": "developer",
                    "context": "ts biased and gendered language in orange: \n   \nHey guys, we're excited to announce a new front-end developer will assume the leadership role. Taylor has extensive expertise and a strong technical background.",
                    "category": "gendered",
                    "subcategory": "titles",
                    "start": 126,
                    "end": 135,
                    "alternatives": [
                        {
                            "text": "they"
                        },
                        {
                            "text": "development"
                        },
                        {
                            "text": "development team"
                        },
                        {
                            "text": "developers"
                        },
                        {
                            "text": "colleague in development"
                        }
                    ],
                    "label": "Gendered: Titles",
                    "explanation": {
                        "text": "Male generic doesn’t address all genders",
                        "icon": "😟",
                        "url": "https://www.witty.works/en/categories/gendered#titles"
                    },
                    "gravity": 2
                },
                {
                    "text": "leadership",
                    "context": "guage in orange: \n   \nHey guys, we're excited to announce a new front-end developer will assume the leadership role. Taylor has extensive expertise and a strong technical background.\n\n \n\nWitty highlights inclus",
                    "category": "gendered",
                    "subcategory": "leadership",
                    "start": 152,
                    "end": 162,
                    "alternatives": [
                        {
                            "text": "guidance"
                        },
                        {
                            "text": "servant leadership"
                        },
                        {
                            "text": "inspiration"
                        },
                        {
                            "text": "care"
                        },
                        {
                            "text": "encouragement"
                        },
                        {
                            "text": "tutelage"
                        },
                        {
                            "text": "guardianship"
                        },
                        {
                            "text": "upper management"
                        },
                        {
                            "text": "servant leaderships"
                        },
                        {
                            "text": "guardianships"
                        }
                    ],
                    "label": "Gendered: Leadership stereotype",
                    "explanation": {
                        "text": "Traditional leadership vocabulary",
                        "icon": "😟",
                        "url": "https://www.witty.works/en/categories/gendered#leadership_stereotype"
                    },
                    "gravity": 2
                },
                {
                    "text": "inclusive",
                    "context": "ership role. Taylor has extensive expertise and a strong technical background.\n\n \n\nWitty highlights inclusive terms in green:\n \nWe are a creative team.\n\n \n   \nWitty corrects grammar and spelling mistakes. They",
                    "category": "inclusive",
                    "subcategory": "d_and_i",
                    "start": 256,
                    "end": 265,
                    "alternatives": [],
                    "label": "Inclusive: Diversity & Inclusion",
                    "explanation": {
                        "text": "Emphasizes value of diversity, equity and inclusion",
                        "icon": "✅",
                        "url": "https://www.witty.works/en/categories/inclusive#diversity_&_inclusion"
                    }
                },
                {
                    "text": "creative",
                    "context": "ertise and a strong technical background.\n\n \n\nWitty highlights inclusive terms in green:\n \nWe are a creative team.\n\n \n   \nWitty corrects grammar and spelling mistakes. They are highlighted in red:\n\nThis is a",
                    "category": "inclusive",
                    "subcategory": "communal",
                    "start": 293,
                    "end": 301,
                    "alternatives": [],
                    "label": "Inclusive: Communal",
                    "explanation": {
                        "text": "Emphasizes cooperative attributes",
                        "icon": "✅",
                        "url": "https://www.witty.works/en/categories/inclusive#communal"
                    }
                },
                {
                    "text": "team",
                    "context": "d a strong technical background.\n\n \n\nWitty highlights inclusive terms in green:\n \nWe are a creative team.\n\n \n   \nWitty corrects grammar and spelling mistakes. They are highlighted in red:\n\nThis is a spell",
                    "category": "inclusive",
                    "subcategory": "communal",
                    "start": 302,
                    "end": 306,
                    "alternatives": [],
                    "label": "Inclusive: Communal",
                    "explanation": {
                        "text": "Emphasizes cooperative attributes",
                        "icon": "✅",
                        "url": "https://www.witty.works/en/categories/inclusive#communal"
                    }
                },
                {
                    "text": "actually",
                    "context": "elling mistacke. \n  \n\n\nWait... there is more. Witty highlights style issues in yellow:\n    \nThis is actually a very long meeting.",
                    "category": "style",
                    "subcategory": "filler",
                    "start": 503,
                    "end": 511,
                    "alternatives": [
                        {
                            "remove": true
                        }
                    ],
                    "label": "Style: Filler Words",
                    "explanation": {
                        "text": "Filler words make understanding harder",
                        "icon": "😟",
                        "url": "https://www.witty.works/en/categories/style#filler_words"
                    },
                    "gravity": 3
                },
                {
                    "text": "very",
                    "context": "acke. \n  \n\n\nWait... there is more. Witty highlights style issues in yellow:\n    \nThis is actually a very long meeting.",
                    "category": "style",
                    "subcategory": "filler",
                    "start": 514,
                    "end": 518,
                    "alternatives": [
                        {
                            "remove": true
                        }
                    ],
                    "label": "Style: Filler Words",
                    "explanation": {
                        "text": "Filler words make understanding harder",
                        "icon": "😟",
                        "url": "https://www.witty.works/en/categories/style#filler_words"
                    },
                    "gravity": 3
                },
                {
                    "text": "expertise",
                    "context": "excited to announce a new front-end developer will assume the leadership role. Taylor has extensive expertise and a strong technical background.\n\n \n\nWitty highlights inclusive terms in green:\n \nWe are a creati",
                    "category": "unconscious_bias",
                    "subcategory": "agentic",
                    "start": 190,
                    "end": 199,
                    "alternatives": [
                        {
                            "text": "competency"
                        },
                        {
                            "text": "understanding"
                        },
                        {
                            "text": "know-how"
                        },
                        {
                            "text": "capacity"
                        },
                        {
                            "text": "skill"
                        },
                        {
                            "text": "insight"
                        },
                        {
                            "text": "substantial experience"
                        },
                        {
                            "text": "assistance",
                            "context": "provided by someone with a specified ability"
                        }
                    ],
                    "label": "Biased language: Agentic",
                    "explanation": {
                        "text": "Doesn’t feel cooperative nor supportive",
                        "icon": "😒",
                        "url": "https://www.witty.works/en/categories/biased_language#agentic"
                    },
                    "gravity": 2
                },
                {
                    "text": "strong",
                    "context": "nce a new front-end developer will assume the leadership role. Taylor has extensive expertise and a strong technical background.\n\n \n\nWitty highlights inclusive terms in green:\n \nWe are a creative team.",
                    "category": "unconscious_bias",
                    "subcategory": "agentic",
                    "start": 206,
                    "end": 212,
                    "alternatives": [
                        {
                            "text": "stable"
                        },
                        {
                            "text": "steady"
                        },
                        {
                            "text": "full"
                        },
                        {
                            "text": "calm"
                        },
                        {
                            "text": "reliable"
                        },
                        {
                            "text": "trusted"
                        },
                        {
                            "text": "dependable"
                        },
                        {
                            "text": "able"
                        },
                        {
                            "text": "sound"
                        }
                    ],
                    "label": "Biased language: Agentic",
                    "explanation": {
                        "text": "Doesn’t feel cooperative nor supportive",
                        "icon": "😒",
                        "url": "https://www.witty.works/en/categories/biased_language#agentic"
                    },
                    "gravity": 2
                }
            ],
            "language": "en",
            "limit_reached": false
        }
    },
    "elements_chain": ""
}

Describe the solution you'd like

Ability to define “virtual” events for specific event types.

So in this case I would define that for any event of type “check”, define a virtual event “result” for each element in the response.results array.

I can then run analytics on these “virtual” events just like on normal events.

Describe alternatives you've considered

A plugin that creates actual events for each element in the response.results array. The drawback here is that it then doesn’t make the relationship between the result elements obvious (one would need to create some on the fly ID to link all the result events together.

It obviously also has billing implications.

Additional context

Generally on the capturing side I want to do as little work as possible, so ideally the work would be done inside posthog.

Thank you for your feature request – we love each and every one!

lsmith77 commented 1 year ago

this is a plugin that would split array elements into their own events to allow them to be used for aggregations on insights: https://github.com/PostHog/integrations-repository/pull/21