Skip to content

Commit 9e0b788

Browse files
committed
Take care of push calls that happen after TD was loaded
1 parent 0219cfb commit 9e0b788

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/telemetrydeck.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class TelemetryDeck {
4141
*
4242
* @returns {Promise<void>}
4343
*/
44-
push([method, data] = []) {
45-
return this[method](data);
44+
push() {
45+
return this.ingest(Array.from(arguments));
4646
}
4747

4848
/**

tests/telemetrydeck.test.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,39 @@ describe('TelemetryDeck.signal()', () => {
7171
});
7272
});
7373

74+
test('sends signal to TelemetryDeck after TD was loaded', async () => {
75+
window.location.href = 'https://nasa.gov';
76+
77+
const spy = jest.spyOn(window, 'fetch');
78+
const td = new TelemetryDeck();
79+
await td.push(['app', 'foo'], ['user', 'bar'], ['signal']);
80+
81+
expect(spy).toHaveBeenCalledTimes(1);
82+
expect(spy).toHaveBeenCalledWith('https://nom.telemetrydeck.com/v1/', {
83+
body: JSON.stringify([
84+
{
85+
appID: 'foo',
86+
clientUser: 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9',
87+
sessionID: 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9',
88+
type: 'pageview',
89+
payload: [
90+
`url:${location.href}`,
91+
`useragent:${navigator.userAgent}`,
92+
`locale:${navigator.language}`,
93+
`platform:${navigator.userAgentData ?? ''}`,
94+
`vendor:${navigator.vendor}`,
95+
`telemetryClientVersion:JavaScriptSDK ${version}`,
96+
],
97+
},
98+
]),
99+
headers: {
100+
'Content-Type': 'application/json',
101+
},
102+
method: 'POST',
103+
mode: 'cors',
104+
});
105+
});
106+
74107
test('sends signals to TelemetryDeck with additional payload data', async () => {
75108
const spy = jest.spyOn(window, 'fetch');
76109
const queue = [['app', 'foo'], ['user', 'bar'], ['signal'], ['signal', { baz: 'bat' }]];

0 commit comments

Comments
 (0)