Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/api/conversions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ class ConversionsAPI {
const options = Config.get();

const name = params.name;
const userId = params.userId || Storage.getItem(Storage.USER_ID);
const deviceId = params.deviceId || Device.getDeviceId();
const installId = params.installId || Device.getInstallId();
const metadata = params.metadata || {};
const createdAt = params.createdAt;

const id = Storage.getItem(Storage.ID);
const userId = params.userId || Storage.getItem(Storage.USER_ID);
const deviceId = params.deviceId || Device.getDeviceId();
const installId = params.installId || Device.getInstallId();

if (params.revenue) {
metadata.revenue = params.revenue;
}

const data: any = {
id,
name,
userId,
deviceId,
Expand Down
7 changes: 7 additions & 0 deletions src/api/track.ts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also send _id up in track if it exists (makes subsequent tracks more performant).

Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,18 @@ class TrackAPI {
_id,
} as RadarTrackVerifiedResponse;

if (user) {
Storage.setItem(Storage.ID, user._id);
}

if (options.debug) {
trackRes.response = response;
}

return trackRes;
}

// unverified track
response = await Http.request({
method: 'POST',
path: 'track',
Expand All @@ -204,6 +209,8 @@ class TrackAPI {
location,
} as RadarTrackResponse;

Storage.setItem(Storage.ID, user?._id);

if (options.debug) {
trackRes.response = response;
}
Expand Down
11 changes: 11 additions & 0 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Logger from './logger';
class Storage {

// local storage key definitions for identifying track users
public static get ID() {
return 'radar-id';
}
public static get USER_ID() {
return 'radar-userId';
}
Expand Down Expand Up @@ -41,6 +44,14 @@ class Storage {
if (!storage) {
return;
}
// clear id if user_id doesn't match previous
if (key == this.USER_ID) {
const previousUserId = this.getItem(this.USER_ID);
if (previousUserId !== value) {
storage.removeItem(this.ID);
console.log("User id mismatch, removing ID");
}
}
if (value === undefined || value === null) {
return;
}
Expand Down