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

Custom events (tags) #81

Closed
s-jakob opened this issue Jun 18, 2019 · 14 comments
Closed

Custom events (tags) #81

s-jakob opened this issue Jun 18, 2019 · 14 comments

Comments

@s-jakob
Copy link
Contributor

s-jakob commented Jun 18, 2019

To mark special events in the recording it would be good to have the ability to add custom events. I think the type for this should be "tags". Similar to Google gtag events:
https://developers.google.com/gtagjs/reference/event

In the data field there should be fields like:

  • name (e.q. 'add_to_card', 'checkout') -> string
  • params (e.q. products added) -> JS Object

To add an tag an function can be added:

rrwebTag('add_to_card', {
    product: '12123',
    qty: 1,
    price: 20
})

This tags can then be displayed during the playback as custom colored marker. The color can be defined when initializing the player as an JS Object:

const events = YOUR_EVENTS;

const replayer = new rrweb.Replayer(events, {
    tags: {
        'add_to_card': '#453222',
        'checkout': '#885942'
    }
});
replayer.play();
@s-jakob
Copy link
Contributor Author

s-jakob commented Jun 18, 2019

Another option could be to add all possible custom tags when initializing the recorder and set an ID:

rrwebRecord({
     emit(event) {
         addEvent(event);
     },
    tags: {
        'add_to_card': 1,
        'checkout': 2
    }
})

This IDs then get added to an offset (e.q. 1000) and set as type in the event when a tag is added. If the custom tag is not in the list the tags is ignored. The rrweb event object would then looks like this for the event 'add_to_card':

{
    type: 1001,
    data: {
        product: '12123',
        qty: 1,
        price: 20
    }
}

This would make the DB search easier when looking for recordings with this tag.

@Yuyz0112
Copy link
Member

Thanks for the proposal!

The custom event is one of the most frequently asked features. And I want to make sure what's the scene that an event must be stored with other rrweb events.

From your proposal, I found the replayer awareness is one of the good points that we should integrate this feature into rrweb. It would be nice if you can share more usages about the custom event.

Thanks a lot.

@s-jakob
Copy link
Contributor Author

s-jakob commented Jun 18, 2019

I need the tags to filter session recordings, which had specific events. Like in my example 'User added product to card' or 'User made a purchase'.

@Yuyz0112
Copy link
Member

Ok, and you will try to query events/tags and find them sessions to make the filter right?

@Yuyz0112
Copy link
Member

Yuyz0112 commented Jun 25, 2019

@s-jakob

Does something like this look good to you?

The data structure:

enum EventType {
  DomContentLoaded,
  Load,
  FullSnapshot,
  IncrementalSnapshot,
  Meta,
+ Custom,
}

+type customEvent<T = unknown> = {
+  type: EventType.Custom;
+  data: {
+    tag: string;
+    payload: T;
+  };
+};

type event =
  | domContentLoadedEvent
  | loadedEvent
  | fullSnapshotEvent
  | incrementalSnapshotEvent
  | metaEvent
+ | customEvent;

and the API:

function addEvent<T>(tag: string, payload: T) {
  emit({
    type: EventType.Custom,
    data: {
      tag,
      payload
    }
  })
}

@s-jakob
Copy link
Contributor Author

s-jakob commented Jun 25, 2019

Hi @Yuyz0112 this looks perfect. I will do the filter on the server side. So i think there is no need für any other changes on the client side.
Thank you very much. This helps a lot.

@marcospassos
Copy link
Contributor

@Yuyz0112 I believe the pa tag should be part of the payload, as not every custom event requires it.

@Yuyz0112
Copy link
Member

@marcospassos
@s-jakob shows an interesting usage of show tags in the replayer like this:

const replayer = new rrweb.Replayer(events, {
    tags: {
        'add_to_card': '#453222',
        'checkout': '#885942'
    }
});

So I think it is a good idea to add the first-class support for the tag system than a general key in the payload.

Yuyz0112 added a commit that referenced this issue Jul 24, 2019
This is the record side impl of custom event, according to the
issue, we may also add first-class support for the custom event
tag like display color labels in the replayer-ui.
@Yuyz0112
Copy link
Member

Has added the client-side addCustomEvent function, will update the docs later.

Yuyz0112 added a commit that referenced this issue Aug 12, 2019
This patch introduce a breaking change in rrweb-record's API, so
we will revert it in 0.7.x and release it in 0.8.
Yuyz0112 added a commit that referenced this issue Aug 12, 2019
This reverts commit 835161c.
@heathdutton
Copy link

heathdutton commented Apr 17, 2020

Looks like this is a live feature, but undocumented. Is it safe to use? I ask because of the reversions :)

@Yuyz0112
Copy link
Member

@heathdutton Yep, it's stable now.

@rifaideen
Copy link
Contributor

rifaideen commented May 22, 2020

@Yuyz0112 - Is this added?

Displaying tag colors on the player timeline like the below:

const replayer = new rrweb.Replayer(events, {
    tags: {
        'add_to_card': '#453222',
        'checkout': '#885942'
    }
});

I'm trying to test this functionality in rrweb-player adding tags options doesn't reflect any changes in the player timeline.

import Player from 'rrweb-player';

const player = new Player({
        target: document.getElementById('preview'),
        data: {
          events: recordings,
          autoPlay: false,
        },
        tags: {
          foo: '#453222',
        },
      });

@Yuyz0112
Copy link
Member

@rifaideen nope, not implmented yet.

@rifaideen
Copy link
Contributor

@Yuyz0112 - ah ok. It would be great if you have any examples on achieving the similar result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants