Skip to content

Commit

Permalink
Fix self-desc events
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Jan 16, 2025
1 parent 873d14c commit 1a4934d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 4 additions & 3 deletions plugins/browser-plugin-webview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Logger, SelfDescribingEvent, SelfDescribingJson } from '@snowplow/track
import { base64urldecode } from './utils';

type WebViewPluginOptions = {
/** Provide a list of tracker namespaces to forward events to.
/**
* Provide a list of tracker namespaces to forward events to.
* By default, the events will be forwarded to the default mobile tracker.
*/
trackerNamespaces?: string[];
Expand Down Expand Up @@ -59,10 +60,10 @@ export function WebViewPlugin(configuration?: WebViewPluginOptions): BrowserPlug

function getSelfDescribingEventData(payload: Payload): SelfDescribingEvent | undefined {
if (payload.ue_pr) {
return JSON.parse(payload.ue_pr as string);
return JSON.parse(payload.ue_pr as string).data;
} else if (payload.ue_px) {
let decoded = base64urldecode(payload.ue_px as string);
return JSON.parse(decoded);
return JSON.parse(decoded).data;
}
return undefined;
}
Expand Down
14 changes: 4 additions & 10 deletions plugins/browser-plugin-webview/test/webview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ describe('WebView plugin', () => {
maxYOffset: undefined,
},
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0',
data: {
schema: 'iglu:com.snowplowanalytics.snowplow.media/play_event/jsonschema/1-0-0',
data: { a: 'b' },
},
schema: 'iglu:com.snowplowanalytics.snowplow.media/play_event/jsonschema/1-0-0',
data: { a: 'b' },
},
context: [
{
Expand Down Expand Up @@ -170,11 +167,8 @@ describe('WebView plugin', () => {
url: expect.any(String),
},
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0',
data: {
schema: 'iglu:com.snowplowanalytics.snowplow/example/jsonschema/1-0-0',
data: { hello: 'world' },
},
schema: 'iglu:com.snowplowanalytics.snowplow/example/jsonschema/1-0-0',
data: { hello: 'world' },
},
context: [
{
Expand Down

0 comments on commit 1a4934d

Please sign in to comment.