Skip to content
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

Create content analytics query endpoint that doesn't require map #30521

Closed
john-thomas-dotcms opened this issue Oct 30, 2024 · 2 comments · Fixed by #30847, #30869 or #30899
Closed

Create content analytics query endpoint that doesn't require map #30521

john-thomas-dotcms opened this issue Oct 30, 2024 · 2 comments · Fixed by #30847, #30869 or #30899

Comments

@john-thomas-dotcms
Copy link
Contributor

Parent Issue

No response

User Story

As a developer, I want to be able to easily perform content analytics queries via API, without having to build a JSON structure or map.

Currently, for content analytics, we support both the native CubeJS query format, and a simpler query format which places each query attribute into a single map. The map simply combines multiple query attributes into a single structure; but it requires the developer to create that structure, rather than allowing them to just submit those attributes separately.

We will create an API endpoint that allows passing each of the query attributes as a separate parameter. This will allow developers to get the analytics query results with a single API call, without the need to build a separate structure to pass into the query (e.g. a standard POST body will work, rather than a more complex nested structure).

The query attributes this endpoint must support match those currently supported in the simple query map. This includes:

  1. Measurables
  2. Dimensions
  3. Time Dimensions
  4. Filter
  5. Order

So, the endpoint should take 5 parameters (one for each of the above attributes).

Details:

  • Each of the params takes a string.
  • The only params that are required are 1 and 2 (Measurables and Dimensions).
    • The others are all optional.
    • Users must be able to supply any one of the optional parameters without having to provide any other optional params.
      • If necessary, this can be handled by passing in empty strings for unused parameters.

Acceptance Criteria

  1. A new API endpoint exists to submit an analytics query without using a map.
  2. The endpoint supports the following query attributes - each as a separate parameter to the endpoint.
    1. Measurables (required)
    2. Dimensions (required)
    3. Time Dimensions (optional)
      • If not supplied, defaults to "Last week"
    4. Filter (optional)
      • If not supplied, no filter is used
    5. Order (optional)
      • If not supplied, sorts by the first Measurable, descending
  3. Each of the params takes a string.
    • No params use or require double quotes anywhere in the strings.
  4. Users can supply any one or two of the optional parameters without having to provide the other optional param(s).
  5. The result format of the endpoint is identical to the result format of the current query endpoint (the one that requires a map).

Proposed Objective

Technical User Experience

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

@john-thomas-dotcms john-thomas-dotcms moved this from New to Next 1-3 Sprints in dotCMS - Product Planning Oct 30, 2024
@john-thomas-dotcms john-thomas-dotcms moved this from Next 1-3 Sprints to Current Sprint Backlog in dotCMS - Product Planning Nov 27, 2024
@jcastro-dotcms jcastro-dotcms moved this from Current Sprint Backlog to In Progress in dotCMS - Product Planning Nov 27, 2024
@jcastro-dotcms jcastro-dotcms self-assigned this Nov 27, 2024
jcastro-dotcms added a commit that referenced this issue Nov 29, 2024
…e Strings to query for Content Analytics data
@jcastro-dotcms jcastro-dotcms moved this from In Progress to In Review in dotCMS - Product Planning Dec 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 5, 2024
…e Strings to query for Content Analytics data (#30847)

### Proposed Changes
* This code change allows users to pass down simple Strings to query for
Content Analytics data.
* Considering the formatting of different values, a special notation
must be used to specify certain parameters in the URL path.
* You can do a POST REST call using a JSON body like this one:
```json
{
    "measures": "request.count request.totalSessions",
    "dimensions": "request.host request.whatAmI request.url",
    "timeDimensions": "request.createdAt:day:Last month",
    "filters": "request.totalRequest gt 0:request.whatAmI contains PAGE,FILE",
    "order": "request.count asc:request.createdAt asc",
    "limit": 5,
    "offset": 0
}
```
The following must be taken into account when putting a query together:
* Measures: Values are separated by blank spaces: `request.count
request.totalSessions`
* Dimensions: Values are separated by blank spaces: `request.host
request.whatAmI request.url`
* Time Dimensions: Values are separated by colons:
`request.createdAt:day:This month` . The second parameter 'day' -- the
"granularity" parameter -- is optional.
* Filters: Values are separated by colons: `request.totalRequest gt
0:request.whatAmI contains PAGE,FILE` . In this case, you're filtering
by the number of requests, and the type of object being queried: Pages
and Files.
* Order: Values are separated by colon: `request.count
asc:request.createdAt asc`
  * Limit: Value is provided as is: `50`
  * Offset: Value is provided as is: `0`
@jcastro-dotcms jcastro-dotcms moved this from In Review to In Progress in dotCMS - Product Planning Dec 5, 2024
jcastro-dotcms added a commit that referenced this issue Dec 6, 2024
…e Strings to query for Content Analytics data
@jcastro-dotcms jcastro-dotcms moved this from In Progress to In Review in dotCMS - Product Planning Dec 6, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 6, 2024
…e Strings to query for Content Analytics data (#30869)

### Proposed Changes
* After discussion with the team, here's the new data format for the
simple String query. By default, the `request` scheme is prepended to
the appropriate terms so users won't have to repeat so many times:
```json
{
    "measures": "count,totalSessions",
    "dimensions": "host,whatAmI,url",
    "timeDimensions": "createdAt,day:Last month",
    "filters": "totalRequest gt 0,whatAmI contains PAGE||FILE",
    "order": "count asc,createdAt asc",
    "limit": 50,
    "offset": 0
}
```
If you want to set a specific scheme, just pass it down in the JSON body
like this:
```json
{
    "scheme": "YOUR-SCHEME-NAME-HERE",
     ...
     ...
}
```
The following must be taken into account when putting a query together:
  * Measures: Values are separated by commas: `count,totalSessions`
  * Dimensions: Values are separated by commas: `host,whatAmI,url`
* Time Dimensions: Values are separated by a comma: `createdAt,day:Last
month` . The second parameter 'day' -- the "granularity" parameter -- is
optional, and separated from the date range by a colon.
* Filters: Values are separated by commas: `totalRequest gt 0,whatAmI
contains PAGE||FILE` . In the `contains` clause, values are separated by
`||`.
  * Order: Values are separated by comma: `count asc,createdAt asc`
  * Limit: Value is provided as is: `50`
  * Offset: Value is provided as is: `0`

This PR fixes: #30521
@github-project-automation github-project-automation bot moved this from In Review to Internal QA in dotCMS - Product Planning Dec 6, 2024
@jcastro-dotcms jcastro-dotcms moved this from Internal QA to In Progress in dotCMS - Product Planning Dec 9, 2024
@jcastro-dotcms jcastro-dotcms reopened this Dec 9, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Current Sprint Backlog in dotCMS - Product Planning Dec 9, 2024
@jcastro-dotcms jcastro-dotcms moved this from Current Sprint Backlog to In Progress in dotCMS - Product Planning Dec 9, 2024
jcastro-dotcms added a commit that referenced this issue Dec 9, 2024
… Strings to query for Content Analytics data
@victoralfaro-dotcms
Copy link
Contributor

victoralfaro-dotcms commented Dec 10, 2024

Tested in dotcms/dotcms:trunk_fc6ec2a

After set a local analytics infrastructure and set a DOT_FEATURE_FLAG_CONTENT_ANALYTICS env-var to true I've navigated through http://localhost:8080 site to generate CA data.

I ran the following command to get data:

curl --location 'http://localhost:8080/api/v1/analytics/content' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--header 'Cookie: JSESSIONID=42863DA6475D1E0BC673F4BF328BFFE5' \
--data '{
    "measures": "count,totalSessions",
    "dimensions": "host,whatAmI,url",
    "filters": "totalRequest gt 0,whatAmI contains PAGE||FILE",
    "order": "count asc,createdAt asc",
    "limit": 20,
    "offset": 0
}'

And this is what I get:

{
    "entity": [
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/e7ceee89-3cc5-4e35-9795-5927ac88ad89/image/w/370/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/68434398-fa40-410a-89ac-3fad66f28630/image/280h/50q/k2-mens-mindbender-99ti-skis-1.jpeg",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/37a75e1d-916d-4820-a00a-72bf64625fc1/image/280h/50q/Gyde Calor Heated Mens Vest 1.png",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/de22b173-edc0-42f0-845f-e579903924f6/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/37a75e1d-916d-4820-a00a-72bf64625fc1/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/activities/sport-fishing",
            "request.whatAmI": "PAGE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/f1d378c9-b784-45d0-a43c-9790af678f13/image/w/370/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/53733761-4836-4dca-8787-81660feeee58/image/50q/1200w/footer-image.jpg",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/df26d95c-4f1f-4503-ac81-8176bb1c417d/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/cfef69fa-de38-4105-9cc9-a30f3e6724d7/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/09841761-aea5-4a1c-a3f3-21e0bc9f7124/image/130h/130ch/130cw/80q/13ro/wetsuit-1.jpg",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/7f2f6de7-554a-4f56-b3f3-c09c0a09b610/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/activities/snowmobiling",
            "request.whatAmI": "PAGE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/5e1076ad-e335-4a29-a956-f0094f8455d2/image/460h/460ch/460cw/80q/13ro/hiking-stick-1.jpeg",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/activities/surfing",
            "request.whatAmI": "PAGE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/654cc765-50be-4ce9-af0d-3748862f8edc/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/4e293f1c-c55e-417a-b5ae-2a09c27dc360/image1/189h/50q/",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/cbd042ff-1225-4cd9-8c6b-eed027f6289d/image/460h/460ch/460cw/80q/13ro/dress-sweater.jpg",
            "request.whatAmI": "FILE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/store/products/black-diamond-trail-pro-shock-trekking-poles",
            "request.whatAmI": "PAGE"
        },
        {
            "request.count": "1",
            "request.host": "",
            "request.totalSessions": "1",
            "request.url": "/dA/0f14f82b-b225-4213-99dc-cad27227533f/image1/189h/50q/",
            "request.whatAmI": "FILE"
        }
    ],
    "errors": [],
    "i18nMessagesMap": {},
    "messages": [],
    "pagination": null,
    "permissions": []
}

@victoralfaro-dotcms victoralfaro-dotcms removed their assignment Dec 10, 2024
@victoralfaro-dotcms victoralfaro-dotcms moved this from Internal QA to QA - Backlog in dotCMS - Product Planning Dec 10, 2024
@dsilvam dsilvam moved this from QA - Backlog to Done in dotCMS - Product Planning Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment