Skip to content

Add user_id to SDK on .com & Limit snowplow events in storage

Ankit Panchal requested to merge 415556-add-user_id-browser-sdk into master

What does this MR do and why?

Implements gitlab-org/analytics-section/product-analytics/gl-application-sdk-browser#40 (closed) / #425948 (closed) & #415556 (closed)

This MR sends user_id field to Browser SDK. We have added pseudonymization in the previous MR

We are now limiting snowplow events stored in localStorage to 100 instead of 1000 (default) , I have already updated that limit for Browser SDK in MR

How to set up and validate locally

Here, We need to verify that user_id is being passed via Browser SDK. We have tested pseudonymization working in previous MR and snowplow is limited to 100 in local storage.

Validate user_id is being passed:

  1. Make sure snowplow micro is running along with GDK. here are the steps to run it. Make sure it is not running on 9091 as browser sdk collector is running on that port.
  2. Setup devkit in local.
  3. Enable feature flag browsersdk_tracking and gl_analytics_tracking
rails c
Feature.enable(:browsersdk_tracking)
Feature.enable(:gl_analytics_tracking)
  1. This feature will only be supported for Gitlab.com, so make sure you make Gitlab.com? method to true in lib/gitlab.rb and restart gdk.

      def self.com?
        true
      end
  2. Create project in devkit with below curl and copy the app_id received.

    curl -X POST http://localhost:4567/setup-project/[project_name] -u test:test
  3. Setup below env variables in gdk terminal and restart gdk.

export GITLAB_ANALYTICS_URL=http://localhost:9091
export GITLAB_ANALYTICS_ID=<app_id received from step 5>
  1. On browser, reload any page. Check snowplow plugin tab, there will be user id being passed.

Screenshot 2023-10-31 at 11.57.39 AM.png

Validate local storage limit :

Prerequisite: Install an ad blocker in your browser (I've tried it with uBlock). This will block all the snowplow request and it will be pushed to local storage.

  1. Just to verify that the limit on localStorage is working correctly, change the limit to 1 instead of 100 here
  2. Verify that in the snowplowOutQueue_gl_post2 key of localStorage maximum one event is being present even after multiple reloads.

Screenshot 2023-10-31 at 12.15.29 PM.png

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #415556 (closed)

Edited by Ankit Panchal

Merge request reports