Skip to content

Commit 6ae82b6

Browse files
committed
Tidy code
1 parent a169a8f commit 6ae82b6

File tree

5 files changed

+96
-100
lines changed

5 files changed

+96
-100
lines changed

src/api.ts

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,40 @@ export interface SelfDescribingEvent {
3838
}
3939

4040
/**
41-
* A Structured Event
42-
* A classic style of event tracking, allows for easier movement between analytics
43-
* systems. A loosely typed event, creating a Self Describing event is preferred, but
44-
* useful for interoperability.
41+
* Event properties that are sent directly, not as part of a self-describing schema.
42+
* These properties will have their own column in the warehouse event table.
4543
*/
46-
export interface StructuredEvent {
47-
/** Name you for the group of objects you want to track e.g. "media", "ecomm". */
48-
category: string;
49-
/** Defines the type of user interaction for the web object. */
50-
action: string;
51-
/** Identifies the specific object being actioned. */
44+
export interface AtomicProperties {
45+
/** Type of event, e.g. "pp" for page ping. */
46+
eventName?: string;
47+
/** Version of the tracker used. */
48+
trackerVersion?: string;
49+
/** The browser useragent. */
50+
useragent?: string;
51+
/** For page view events. The page URL. */
52+
url?: string;
53+
/** For page view events. The page title. */
54+
title?: string;
55+
/** For page view events. The referrer URL. */
56+
referrer?: string;
57+
/** For structured events. Name for the group of objects you want to track. */
58+
category?: string;
59+
/** For structured events. Defines the type of user interaction for the web object. */
60+
action?: string;
61+
/** For structured events. Identifies the specific object being actioned. */
5262
label?: string;
53-
/** Describes the object or the action performed on it. */
63+
/** For structured events. Describes the object or the action performed on it. */
5464
property?: string;
55-
/** Quantifies or further describes the user action. */
65+
/** For structured events. Quantifies or further describes the user action. */
5666
value?: number;
67+
/** For page ping events. The minimum X offset. */
68+
minXOffset?: number;
69+
/** For page ping events. The maximum X offset. */
70+
maxXOffset?: number;
71+
/** For page ping events. The minimum Y offset. */
72+
maxYOffset?: number;
73+
/** For page ping events. The maximum Y offset. */
74+
minYOffset?: number;
5775
}
5876

5977
/**
@@ -91,68 +109,30 @@ interface FullPageViewEvent extends PageViewEvent {
91109
referrer?: string;
92110
}
93111

94-
/** Additional data points to set when tracking an event */
95-
export interface CommonEventProperties {
96-
/** Add context to an event by setting an Array of Self Describing JSON */
97-
context?: Array<SelfDescribingJson> | null;
98-
}
99-
100112
/**
101-
* Event properties that are sent directly, not as part of a self-describing schema.
102-
* These properties will have their own column in the warehouse event table.
113+
* A Structured Event
114+
* A classic style of event tracking, allows for easier movement between analytics
115+
* systems. A loosely typed event, creating a Self Describing event is preferred, but
116+
* useful for interoperability.
103117
*/
104-
export interface AtomicProperties {
105-
/** Type of event, e.g. "pp" for page ping. */
106-
eventName?: string;
107-
/** Version of the tracker used. */
108-
trackerVersion?: string;
109-
/** The browser useragent. */
110-
useragent?: string;
111-
/** For page view events. The page URL. */
112-
url?: string;
113-
/** For page view events. The page title. */
114-
title?: string;
115-
/** For page view events. The referrer URL. */
116-
referrer?: string;
117-
/** For structured events. Name for the group of objects you want to track. */
118-
category?: string;
119-
/** For structured events. Defines the type of user interaction for the web object. */
120-
action?: string;
121-
/** For structured events. Identifies the specific object being actioned. */
118+
export interface StructuredEvent {
119+
/** Name you for the group of objects you want to track e.g. "media", "ecomm". */
120+
category: string;
121+
/** Defines the type of user interaction for the web object. */
122+
action: string;
123+
/** Identifies the specific object being actioned. */
122124
label?: string;
123-
/** For structured events. Describes the object or the action performed on it. */
125+
/** Describes the object or the action performed on it. */
124126
property?: string;
125-
/** For structured events. Quantifies or further describes the user action. */
127+
/** Quantifies or further describes the user action. */
126128
value?: number;
127-
/** For page ping events. The minimum X offset. */
128-
minXOffset?: number;
129-
/** For page ping events. The maximum X offset. */
130-
maxXOffset?: number;
131-
/** For page ping events. The minimum Y offset. */
132-
maxYOffset?: number;
133-
/** For page ping events. The maximum Y offset. */
134-
minYOffset?: number;
135129
}
136130

137-
/** Interface for communicating with the Android mobile tracker */
138-
export type SnowplowWebInterfaceV2 = {
139-
trackWebViewEvent: (
140-
atomicProperties: string,
141-
selfDescribingEventData?: string | null,
142-
context?: string | null,
143-
trackers?: Array<string> | null
144-
) => void;
145-
};
146-
147-
/** Interface for communicating with the iOS mobile tracker */
148-
export type WebkitMessageHandlerV2 = {
149-
postMessage: (message: {
150-
atomicProperties: string;
151-
selfDescribingEventData?: string | null;
152-
context?: string | null;
153-
trackers?: Array<string> | null;
154-
}) => void;
155-
};
131+
/** Additional data points to set when tracking an event */
132+
export interface CommonEventProperties {
133+
/** Add context to an event by setting an Array of Self Describing JSON */
134+
context?: Array<SelfDescribingJson> | null;
135+
}
156136

157137
/** Interface for communicating with the Android mobile tracker */
158138
export type SnowplowWebInterface = {
@@ -191,6 +171,16 @@ export type SnowplowWebInterface = {
191171
) => void;
192172
};
193173

174+
/** Interface for communicating with the Android mobile tracker from v6.1+ onwards */
175+
export type SnowplowWebInterfaceV2 = {
176+
trackWebViewEvent: (
177+
atomicProperties: string,
178+
selfDescribingEventData?: string | null,
179+
context?: string | null,
180+
trackers?: Array<string> | null
181+
) => void;
182+
};
183+
194184
/** Interface for communicating with the iOS mobile tracker */
195185
export type WebkitMessageHandler = {
196186
postMessage: (message: {
@@ -205,6 +195,16 @@ export type WebkitMessageHandler = {
205195
}) => void;
206196
};
207197

198+
/** Interface for communicating with the iOS mobile tracker from v6.1+ onwards */
199+
export type WebkitMessageHandlerV2 = {
200+
postMessage: (message: {
201+
atomicProperties: string;
202+
selfDescribingEventData?: string | null;
203+
context?: string | null;
204+
trackers?: Array<string> | null;
205+
}) => void;
206+
};
207+
208208
/** Interface for communicating with the React Native tracker */
209209
export type ReactNativeInterface = {
210210
postMessage: (message: string) => void;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function trackWebViewEvent(
123123
command: 'trackWebViewEvent',
124124
event: {
125125
selfDescribingEventData: event,
126-
...atomicProperties
126+
...atomicProperties,
127127
},
128128
context: entities,
129129
trackers: trackers,

test/androidV2.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1111

12-
import {
13-
trackWebViewEvent,
14-
} from '../src';
12+
import { trackWebViewEvent } from '../src';
1513

1614
describe('Android interface', () => {
1715
let windowSpy: any;
@@ -61,7 +59,7 @@ describe('Android interface', () => {
6159
abc: 1,
6260
},
6361
},
64-
}
62+
};
6563

6664
trackWebViewEvent(atomic, event, null, null);
6765

test/iosV2.test.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1111

12-
import {
13-
trackWebViewEvent,
14-
} from '../src';
12+
import { trackWebViewEvent } from '../src';
1513

1614
describe('iOS interface', () => {
1715
let windowSpy: any;
@@ -36,22 +34,22 @@ describe('iOS interface', () => {
3634
});
3735

3836
it('tracks a webview primitive event', () => {
39-
const atomic = {
40-
eventName: 'pv',
41-
trackerVersion: 'webview',
42-
url: 'http://test.com',
43-
title: 'test title',
44-
};
37+
const atomic = {
38+
eventName: 'pv',
39+
trackerVersion: 'webview',
40+
url: 'http://test.com',
41+
title: 'test title',
42+
};
4543

46-
trackWebViewEvent(atomic, null, null, ['ns1', 'ns2']);
44+
trackWebViewEvent(atomic, null, null, ['ns1', 'ns2']);
4745

48-
expect(messageHandler).toHaveBeenCalledWith({
49-
atomicProperties: JSON.stringify(atomic),
50-
selfDescribingEventData: null,
51-
entities: null,
52-
trackers: ['ns1', 'ns2']
53-
});
46+
expect(messageHandler).toHaveBeenCalledWith({
47+
atomicProperties: JSON.stringify(atomic),
48+
selfDescribingEventData: null,
49+
entities: null,
50+
trackers: ['ns1', 'ns2'],
5451
});
52+
});
5553

5654
it('tracks a webview self-describing event', () => {
5755
const atomic = {
@@ -65,16 +63,16 @@ describe('iOS interface', () => {
6563
abc: 1,
6664
},
6765
},
68-
}
66+
};
6967

7068
trackWebViewEvent(atomic, event, null, null);
7169

7270
expect(messageHandler).toHaveBeenCalledWith({
73-
atomicProperties: JSON.stringify(atomic),
74-
selfDescribingEventData: JSON.stringify(event),
75-
entities: null,
76-
trackers: null
77-
});
71+
atomicProperties: JSON.stringify(atomic),
72+
selfDescribingEventData: JSON.stringify(event),
73+
entities: null,
74+
trackers: null,
75+
});
7876
});
7977

8078
it('adds context entities', () => {
@@ -88,10 +86,10 @@ describe('iOS interface', () => {
8886
trackWebViewEvent({}, null, [entity], null);
8987

9088
expect(messageHandler).toHaveBeenCalledWith({
91-
atomicProperties: '{}',
92-
selfDescribingEventData: null,
93-
entities: JSON.stringify([entity]),
94-
trackers: null
95-
});
89+
atomicProperties: '{}',
90+
selfDescribingEventData: null,
91+
entities: JSON.stringify([entity]),
92+
trackers: null,
93+
});
9694
});
9795
});

test/reactNative.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('React Native interface', () => {
7979
abc: 1,
8080
},
8181
},
82-
}
82+
};
8383

8484
trackWebViewEvent(atomic, event, null, null);
8585

0 commit comments

Comments
 (0)