Get list of date dimensions in chronological order

  Kiến thức lập trình

I would like to get a list of views (any metric really) using the google analytics API.

I used the metrics for screenPageViews and the dimension date.

I do get the metrics, but they are not in chronological order (I want them from the oldest date to the latest date).

An example output is one below;

view date: 20240422
view date: 20240420
view date: 20240424
view date: 20240425
view date: 20240423
*view date: 20240505*
view date: 20240702
view date: 20240421
view date: 20240426
view date: 20240428
view date: 20240429
*view date: 20240704*
view date: 20240501
view date: 20240504
view date: 20240507
view date: 20240514
*view date: 20240707*
view date: 20240430
view date: 20240503
view date: 20240506
view date: 20240510
view date: 20240511
*view date: 20240418*
view date: 20240502
view date: 20240508
view date: 20240512
view date: 20240520

Anomalies are between **
As you can see, the month April (04) starts but then we see, the month 07 appear after month 05, we also see month 04 in the middle and towards the end.

How do I make it such that the dates are from the earlier to the latest?

Below is the payload I am using

{
            "dateRanges": [
                {
                    "startDate": "7daysAgo",
                    "endDate": "today"
                }],

            "dimensions": [
                { "name": "date" }
            ],

            "dimensionFilter": {
                "filter": {
                    "fieldName": "pagePath",
                    "stringFilter": {
                        "matchType": "CONTAINS",
                        "value": "/about"
                    }
                }
            },

            "metrics": [
                { "name": "screenPageViews" }
            ]
        }

I am using JS to process the output. Thanks in advance.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT