diff --git a/api/queries/search/searchCommunities.js b/api/queries/search/searchCommunities.js index 6b52db268e..04537dd2c2 100644 --- a/api/queries/search/searchCommunities.js +++ b/api/queries/search/searchCommunities.js @@ -12,14 +12,16 @@ export default (args: Args, { loaders, user }: GraphQLContext) => { return communitySearchIndex .search({ query: queryString }) .then(content => { - trackQueue.add({ - userId: user.id, - event: events.SEARCHED_COMMUNITIES, - properties: { - queryString, - hitsCount: content.hits ? content.hits.length : 0, - }, - }); + if (user && user.id) { + trackQueue.add({ + userId: user.id, + event: events.SEARCHED_COMMUNITIES, + properties: { + queryString, + hitsCount: content.hits ? content.hits.length : 0, + }, + }); + } if (!content.hits || content.hits.length === 0) return []; const communityIds = content.hits.map(o => o.objectID); diff --git a/api/queries/search/searchCommunityMembers.js b/api/queries/search/searchCommunityMembers.js index 3e0b1ed7ee..a74fe8ec67 100644 --- a/api/queries/search/searchCommunityMembers.js +++ b/api/queries/search/searchCommunityMembers.js @@ -16,14 +16,16 @@ export default (args: Args, { loaders, user }: GraphQLContext) => { return usersSearchIndex .search({ query: queryString, hitsPerPage }) .then(content => { - trackQueue.add({ - userId: user.id, - event: events.SEARCHED_COMMUNITY_MEMBERS, - properties: { - queryString, - hitsCount: content.hits ? content.hits.length : 0, - }, - }); + if (user && user.id) { + trackQueue.add({ + userId: user.id, + event: events.SEARCHED_COMMUNITY_MEMBERS, + properties: { + queryString, + hitsCount: content.hits ? content.hits.length : 0, + }, + }); + } if (!content.hits || content.hits.length === 0) return []; // if no search filter was passed, there's no way to be searching for diff --git a/api/queries/search/searchThreads.js b/api/queries/search/searchThreads.js index 333f752235..b61c1db4c3 100644 --- a/api/queries/search/searchThreads.js +++ b/api/queries/search/searchThreads.js @@ -38,15 +38,17 @@ export default async (args: Args, { loaders, user }: GraphQLContext) => { threadsSearchIndex .search({ query: queryString, filters }) .then(content => { - trackQueue.add({ - userId: user.id, - event: events.SEARCHED_CONVERSATIONS, - properties: { - queryString, - filters, - hitsCount: content.hits ? content.hits.length : 0, - }, - }); + if (user && user.id) { + trackQueue.add({ + userId: user.id, + event: events.SEARCHED_CONVERSATIONS, + properties: { + queryString, + filters, + hitsCount: content.hits ? content.hits.length : 0, + }, + }); + } if (!content.hits || content.hits.length === 0) return null; return content.hits.map(o => ({ diff --git a/api/queries/search/searchUsers.js b/api/queries/search/searchUsers.js index a4857f7511..7a4b89fe30 100644 --- a/api/queries/search/searchUsers.js +++ b/api/queries/search/searchUsers.js @@ -21,14 +21,16 @@ export default (args: Args, { loaders, user }: GraphQLContext) => { ? events.SEARCHED_COMMUNITY_MEMBERS : events.SEARCHED_USERS; - trackQueue.add({ - userId: user.id, - event, - properties: { - queryString, - hitsCount: content.hits ? content.hits.length : 0, - }, - }); + if (user && user.id) { + trackQueue.add({ + userId: user.id, + event, + properties: { + queryString, + hitsCount: content.hits ? content.hits.length : 0, + }, + }); + } if (!content.hits || content.hits.length === 0) return []; diff --git a/package.json b/package.json index f6178bea0f..3b864ac431 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Spectrum", - "version": "2.3.0", + "version": "2.3.1", "license": "BSD-3-Clause", "devDependencies": { "babel-cli": "^6.24.1",