Skip to content

Add Snowplow tracking to audit events date range segmented control

What does this MR do?

This MR adds a Snowplow tracking event to the audit events date range segmented control buttons. Each button will trigger a Snowplow event upon being clicked which we will then use to track the user usage of this feature over time.

Screenshots or Screencasts (strongly suggested)

Screen_Recording_2021-07-23_at_09.29.34

Snowplow micro

Example output
[			
    {
        "contexts": [
            "iglu:com.gitlab/gitlab_standard/jsonschema/1-0-5",
            "iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0",
            "iglu:org.w3/PerformanceTiming/jsonschema/1-0-0"
        ],
        "event": {
            "app_id": "gitlab",
            "base_currency": null,
            "br_colordepth": "24",
            "br_cookies": true,
            "br_family": null,
            "br_features_director": false,
            "br_features_flash": false,
            "br_features_gears": false,
            "br_features_java": false,
            "br_features_pdf": true,
            "br_features_quicktime": false,
            "br_features_realplayer": false,
            "br_features_silverlight": false,
            "br_features_windowsmedia": false,
            "br_lang": "en-GB",
            "br_name": null,
            "br_renderengine": null,
            "br_type": null,
            "br_version": null,
            "br_viewheight": 944,
            "br_viewwidth": 977,
            "collector_tstamp": "2021-07-23T08:22:29.044Z",
            "contexts": {
                "data": [
                    {
                        "data": {
                            "environment": "development",
                            "extra": {},
                            "plan": null,
                            "source": "gitlab-javascript"
                        },
                        "schema": "iglu:com.gitlab/gitlab_standard/jsonschema/1-0-5"
                    },
                    {
                        "data": {
                            "id": "83028318-ab75-4842-ad7b-dd239d16a0fd"
                        },
                        "schema": "iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0"
                    },
                    {
                        "data": {
                            "connectEnd": 1627028477322,
                            "connectStart": 1627028477322,
                            "domComplete": 1627028482387,
                            "domContentLoadedEventEnd": 1627028481730,
                            "domContentLoadedEventStart": 1627028481724,
                            "domInteractive": 1627028480212,
                            "domLoading": 1627028478742,
                            "domainLookupEnd": 1627028477322,
                            "domainLookupStart": 1627028477322,
                            "fetchStart": 1627028477322,
                            "loadEventEnd": 1627028482389,
                            "loadEventStart": 1627028482387,
                            "navigationStart": 1627028477321,
                            "redirectEnd": 0,
                            "redirectStart": 0,
                            "requestStart": 1627028477331,
                            "responseEnd": 1627028478726,
                            "responseStart": 1627028478725,
                            "secureConnectionStart": 0,
                            "unloadEventEnd": 1627028478733,
                            "unloadEventStart": 1627028478732
                        },
                        "schema": "iglu:org.w3/PerformanceTiming/jsonschema/1-0-0"
                    }
                ],
                "schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0"
            },
            "derived_contexts": {},
            "derived_tstamp": "2021-07-23T08:22:29.041Z",
            "doc_charset": "UTF-8",
            "doc_height": 944,
            "doc_width": 962,
            "domain_sessionid": "ee59da52-e638-4432-948f-8091483df26c",
            "domain_sessionidx": 1,
            "domain_userid": "8159ac1a-ddc5-49bb-b4ff-a7fc341fccf4",
            "dvce_created_tstamp": "2021-07-23T08:22:29.002Z",
            "dvce_ismobile": null,
            "dvce_screenheight": 1080,
            "dvce_screenwidth": 3840,
            "dvce_sent_tstamp": "2021-07-23T08:22:29.005Z",
            "dvce_type": null,
            "etl_tags": null,
            "etl_tstamp": "2021-07-23T08:22:29.048Z",
            "event": "struct",
            "event_fingerprint": null,
            "event_format": "jsonschema",
            "event_id": "fa219bbb-aafa-4551-a148-b2e57188ca6f",
            "event_name": "event",
            "event_vendor": "com.google.analytics",
            "event_version": "1-0-0",
            "geo_city": null,
            "geo_country": null,
            "geo_latitude": null,
            "geo_longitude": null,
            "geo_region": null,
            "geo_region_name": null,
            "geo_timezone": null,
            "geo_zipcode": null,
            "ip_domain": null,
            "ip_isp": null,
            "ip_netspeed": null,
            "ip_organization": null,
            "mkt_campaign": null,
            "mkt_clickid": null,
            "mkt_content": null,
            "mkt_medium": null,
            "mkt_network": null,
            "mkt_source": null,
            "mkt_term": null,
            "name_tracker": "gl",
            "network_userid": "bf6d7c1c-4130-4b21-8008-ef4d9f92783b",
            "os_family": null,
            "os_manufacturer": null,
            "os_name": null,
            "os_timezone": "Europe/London",
            "page_referrer": "https://gdk.localhost:3443/groups/gitlab-org/-/audit_events?created_after=2021-07-13&created_before=2021-07-20",
            "page_title": null,
            "page_url": "https://gdk.localhost:3443/groups/gitlab-org/-/audit_events?created_after=2021-07-14&created_before=2021-07-21",
            "page_urlfragment": null,
            "page_urlhost": "gdk.localhost",
            "page_urlpath": "/groups/gitlab-org/-/audit_events",
            "page_urlport": 3443,
            "page_urlquery": "created_after=2021-07-14&created_before=2021-07-21",
            "page_urlscheme": "https",
            "platform": "web",
            "pp_xoffset_max": null,
            "pp_xoffset_min": null,
            "pp_yoffset_max": null,
            "pp_yoffset_min": null,
            "refr_domain_userid": null,
            "refr_dvce_tstamp": null,
            "refr_medium": null,
            "refr_source": null,
            "refr_term": null,
            "refr_urlfragment": null,
            "refr_urlhost": "gdk.localhost",
            "refr_urlpath": "/groups/gitlab-org/-/audit_events",
            "refr_urlport": 3443,
            "refr_urlquery": "created_after=2021-07-13&created_before=2021-07-20",
            "refr_urlscheme": "https",
            "se_action": "click_date_range_button",
            "se_category": "groups:audit_events:index",
            "se_label": "date_range_button_last_7_days",
            "se_property": null,
            "se_value": null,
            "ti_category": null,
            "ti_currency": null,
            "ti_name": null,
            "ti_orderid": null,
            "ti_price": null,
            "ti_price_base": null,
            "ti_quantity": null,
            "ti_sku": null,
            "tr_affiliation": null,
            "tr_city": null,
            "tr_country": null,
            "tr_currency": null,
            "tr_orderid": null,
            "tr_shipping": null,
            "tr_shipping_base": null,
            "tr_state": null,
            "tr_tax": null,
            "tr_tax_base": null,
            "tr_total": null,
            "tr_total_base": null,
            "true_tstamp": null,
            "txn_id": null,
            "unstruct_event": null,
            "user_fingerprint": null,
            "user_id": null,
            "user_ipaddress": "172.17.0.1",
            "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4583.0 Safari/537.36",
            "v_collector": "ssc-2.3.0-stdout$",
            "v_etl": "snowplow-micro-1.1.3-rc3-common-2.0.1",
            "v_tracker": "js-2.17.3"
        },
        "eventType": "struct",
        "rawEvent": {
            "api": {
                "vendor": "com.snowplowanalytics.snowplow",
                "version": "tp2"
            },
            "contentType": "application/json",
            "context": {
                "headers": [
                    "Timeout-Access: <function1>",
                    "Host: localhost:9090",
                    "Connection: keep-alive",
                    "Pragma: no-cache",
                    "Cache-Control: no-cache",
                    "sec-ch-ua: \"Chromium\";v=\"94\", \"Google Chrome\";v=\"94\", \";Not A Brand\";v=\"99\"",
                    "sec-ch-ua-mobile: ?0",
                    "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4583.0 Safari/537.36",
                    "sec-ch-ua-platform: \"macOS\"",
                    "Accept: */*",
                    "Origin: https://gdk.localhost:3443",
                    "Sec-Fetch-Site: cross-site",
                    "Sec-Fetch-Mode: cors",
                    "Sec-Fetch-Dest: empty",
                    "Accept-Encoding: gzip, deflate, br",
                    "Accept-Language: en-GB, en;q=0.9, es-ES;q=0.8, es;q=0.7, en-US;q=0.6",
                    "application/json"
                ],
                "ipAddress": "172.17.0.1",
                "refererUri": null,
                "timestamp": "2021-07-23T08:22:29.044Z",
                "userId": "bf6d7c1c-4130-4b21-8008-ef4d9f92783b",
                "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4583.0 Safari/537.36"
            },
            "parameters": {
                "aid": "gitlab",
                "cd": "24",
                "cookie": "1",
                "cs": "UTF-8",
                "cx": "eyJzY2hlbWEiOiJpZ2x1OmNvbS5zbm93cGxvd2FuYWx5dGljcy5zbm93cGxvdy9jb250ZXh0cy9qc29uc2NoZW1hLzEtMC0wIiwiZGF0YSI6W3sic2NoZW1hIjoiaWdsdTpjb20uZ2l0bGFiL2dpdGxhYl9zdGFuZGFyZC9qc29uc2NoZW1hLzEtMC01IiwiZGF0YSI6eyJlbnZpcm9ubWVudCI6ImRldmVsb3BtZW50Iiwic291cmNlIjoiZ2l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vYWRFdmVudFN0YXJ0IjoxNjI3MDI4NDgyMzg3LCJsb2FkRXZlbnRFbmQiOjE2MjcwMjg0ODIzODl9fV19",
                "ds": "962x944",
                "dtm": "1627028549002",
                "duid": "8159ac1a-ddc5-49bb-b4ff-a7fc341fccf4",
                "e": "se",
                "eid": "fa219bbb-aafa-4551-a148-b2e57188ca6f",
                "f_ag": "0",
                "f_dir": "0",
                "f_fla": "0",
                "f_gears": "0",
                "f_java": "0",
                "f_pdf": "1",
                "f_qt": "0",
                "f_realp": "0",
                "f_wma": "0",
                "lang": "en-GB",
                "p": "web",
                "refr": "https://gdk.localhost:3443/groups/gitlab-org/-/audit_events?created_after=2021-07-13&created_before=2021-07-20",
                "res": "3840x1080",
                "se_ac": "click_date_range_button",
                "se_ca": "groups:audit_events:index",
                "se_la": "date_range_button_last_7_days",
                "sid": "ee59da52-e638-4432-948f-8091483df26c",
                "stm": "1627028549005",
                "tna": "gl",
                "tv": "js-2.17.3",
                "tz": "Europe/London",
                "url": "https://gdk.localhost:3443/groups/gitlab-org/-/audit_events?created_after=2021-07-14&created_before=2021-07-21",
                "vid": "1",
                "vp": "977x944"
            },
            "source": {
                "encoding": "UTF-8",
                "hostname": "localhost",
                "name": "ssc-2.3.0-stdout$"
            }
        },
        "schema": "iglu:com.google.analytics/event/jsonschema/1-0-0"
    },
]

Setup & testing

Note: This feature requires at least GitLab Premium

  1. Make sure that you disable Do not track in your browser, plus any other tracker blockers you might have installed (uBlock, Ghost, PiHole etc)
  2. Enable Snowplow via [HOST]/admin/application_settings/general#js-snowplow-settings, you can use the following for testing purposes:
  Hostname: your-snowplow-collector.net
  App ID: gitlab
  Cookie domain: .your-gitlab-instance.com
  1. Install a browser extension to test the events are sent
    • Note: If you do not have Snowplow micro setup you will get multiple events as it tries to resend them
  2. Visit [HOST]/admin/audit_logs, [HOST]/groups/[GROUP]/-/audit_events and [HOST]/[GROUP]/[PROJECT]/-/audit_events
  3. Click on the Last 7 days, Last 14 days and This month segmented buttons and check that the Snowplow events are sent with the following info:
  Category: `admin:audit_logs:index` | `groups:audit_events:index` | `projects:audit_events:index`
  Action: `click_date_range_button`
  Label: `date_range_button_last_7_days` | `date_range_button_last_14_days` | `date_range_button_last_month`

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #333944 (closed)

Edited by Robert Hunt

Merge request reports