Skip to content

Commit 6732ad7

Browse files
committed
fix: update data keys for compatibility with beta api
1 parent 93e37e7 commit 6732ad7

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

integration/fixtures/streamsql.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/index.umd.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('integration', () => {
3030
if (postData) {
3131
postData = JSON.parse(postData)
3232
}
33-
expect(postData.streamName).toMatch('clickstream')
34-
expect(postData.eventTimestamp).toBeGreaterThan(15e9)
33+
expect(postData.stream).toMatch('clickstream')
34+
expect(postData.data.timestamp).toBeGreaterThan(15e9)
3535
}, 10000)
3636

3737
it('sends page context with url, title, and referrer', async () => {
@@ -42,7 +42,7 @@ describe('integration', () => {
4242
await page.goto(home)
4343
await page.click('button#count-button')
4444
postData = postData && JSON.parse(postData)
45-
expect(postData.context).toMatchObject({
45+
expect(postData.data.context).toMatchObject({
4646
url: await page.url(),
4747
title: await page.title(),
4848
referrer: '',
@@ -51,7 +51,7 @@ describe('integration', () => {
5151
await Promise.all([page.waitForNavigation(), page.click('a')])
5252
await page.click('button#send-button')
5353
postData = postData && JSON.parse(postData)
54-
expect(postData.context).toMatchObject({
54+
expect(postData.data.context).toMatchObject({
5555
url: await page.url(),
5656
title: await page.title(),
5757
referrer: expect.stringMatching(SERVER_URL),
@@ -108,27 +108,27 @@ describe('integration', () => {
108108
await page.type('input#user-input', userId)
109109
await page.click('button#login-button')
110110
postData = postData && JSON.parse(postData)
111-
expect(postData.user).toMatchObject({ id: userId })
111+
expect(postData.data.user).toMatchObject({ id: userId })
112112
postData = undefined // reset for next page
113113

114114
// visit the other page, should persist userId
115115
await Promise.all([page.waitForNavigation(), page.click('a')])
116116
await page.click('button#send-button')
117117
postData = postData && JSON.parse(postData)
118-
expect(postData.user).toMatchObject({ id: userId })
118+
expect(postData.data.user).toMatchObject({ id: userId })
119119
postData = undefined
120120

121121
// do logout, ensure logout sent event does NOT have user id
122122
await page.click('#logout-button')
123123
postData = postData && JSON.parse(postData)
124-
expect(postData.user).toMatchObject({ id: '' })
124+
expect(postData.data.user).toMatchObject({ id: '' })
125125
postData = undefined
126126

127127
// go back and send event from home page, should NOT have user id
128128
await page.goBack()
129129
await page.click('#count-button')
130130
postData = postData && JSON.parse(postData)
131-
expect(postData.user).toMatchObject({ id: '' })
131+
expect(postData.data.user).toMatchObject({ id: '' })
132132
}, 20000)
133133

134134
it('persists user id when coming back to site', async () => {
@@ -145,7 +145,7 @@ describe('integration', () => {
145145
await page.type('input#user-input', userId)
146146
await page.click('button#login-button')
147147
postData = postData && JSON.parse(postData)
148-
expect(postData.user).toMatchObject({ id: userId })
148+
expect(postData.data.user).toMatchObject({ id: userId })
149149
postData = undefined // reset for next page
150150

151151
// visit the other page, should persist userId
@@ -154,7 +154,7 @@ describe('integration', () => {
154154
await page.goto(alt)
155155
await page.click('button#send-button')
156156
postData = postData && JSON.parse(postData)
157-
expect(postData.user).toMatchObject({ id: userId })
157+
expect(postData.data.user).toMatchObject({ id: userId })
158158
}, 8000)
159159

160160
it('calls template functions onIdentify and onUnidentify', async () => {

src/StreamSQL.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ export default class StreamSQLClient implements CoreAPI {
5959
if (!this.pageCtx || !this.identifier) {
6060
this.throwNoInitError()
6161
}
62-
return {
63-
streamName: streamName.toLowerCase(),
64-
eventTimestamp: new Date().getTime(),
62+
const streamsqlData = {
63+
timestamp: new Date().getTime(),
6564
context: {
6665
url: this.pageCtx.location(),
6766
referrer: this.pageCtx.referrer(),
@@ -71,7 +70,11 @@ export default class StreamSQLClient implements CoreAPI {
7170
id: this.identifier.getUser(),
7271
// FUTURE: ability to add other user props
7372
},
74-
data: data || {}
73+
}
74+
const _data = data ? Object.assign({}, streamsqlData, data) : streamsqlData
75+
return {
76+
stream: streamName.toLowerCase(),
77+
data: _data
7578
}
7679
}
7780

0 commit comments

Comments
 (0)