Skip to content

Commit 95a671a

Browse files
committed
change terminology to "userToken", prevent storing customer's statsSessionId in cookie
1 parent cf5f4d4 commit 95a671a

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,42 +336,41 @@ client.setAnalyticsTag('Navigation search');
336336
### Personalization
337337

338338
#### Enable personalization tracking
339-
Enable personalization tracking, personalization token will be included in every stat events as "session ID". <br/>
339+
Enable personalization tracking, user token will be included in every stat events as "session ID". <br/>
340340

341-
Set stats session ID if personalization token is generated by your site.
341+
Set stats session ID if user token is generated by your site.
342342
```js
343-
client.setStatsSessionId(id);
343+
client.setStatsSessionId(userToken);
344344
```
345345

346-
If session ID is not set, a UUID is generated and stored in AddSearch's cookie. Cookie's name: addsearchPersonalizationToken
347-
Specify how many days personalization token stay in cookie. By default, it's 180 days.
346+
If session ID is not set, a UUID is generated and stored in AddSearch's cookie. Cookie's name: addsearchUserToken
347+
Specify how many dates user token stay in cookie. Default is 180 dates.
348348
```js
349-
// Defaults - isEnabled: false, expirationDays: 180
350-
client.enablePersonalizationTracking(isEnabled, expirationDays);
349+
// Defaults - isEnabled: false, expirationDates: 180
350+
client.enablePersonalizationTracking(isEnabled, expirationDates);
351351
```
352352

353353

354-
#### Allow storing personalization token in cookie
355-
By default, the value is true. Set it to false when users disallow usage of functional/analytics cookie. <br/>
356-
This method is used when you have a cookie consent popup, and a function handler in case users rejects usage of personalization cookie.
354+
#### Allow storing AddSearch's user token in cookie
355+
By default, the value is true. Set it to false when users reject cookie (AddSearch's cookie can be categorized as functional/analytics cookie).
357356
```js
358357
// Default: true
359358
client.consentAddSearchCookie(false);
360359
```
361360

362361

363-
#### Set user token (for personalized search results)
362+
#### Set user token to search query (for personalized search results)
364363
```js
365364
// Add a user token to the search request (if personalization in use)
366-
client.setUserToken('Personalization token');
365+
client.setUserToken(userToken);
367366
```
368367

369368

370-
#### Get personalization token from AddSearch cookie
371-
Get the personalization token which is stored in AddSearch cookie (if available).
369+
#### Get user token from AddSearch cookie
370+
Get the user token which is stored in AddSearch cookie (if available).
372371
```js
373-
// Get a personalization token
374-
client.getPersonalizationToken();
372+
// Get a user token
373+
client.getUserTokenInPersonalization();
375374
```
376375

377376

src/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ var throttle = require('./throttle');
99
var cookie = require('./cookie');
1010

1111
var API_HOSTNAME = 'api.addsearch.com';
12-
var PERSONALIZATION_TOKEN_COOKIE_NAME = 'addsearchPersonalizationToken';
12+
var USER_TOKEN_COOKIE_NAME = 'addsearchUserToken';
1313

1414
var client = function(sitekey, privatekey) {
1515
this.sitekey = sitekey;
1616
this.privatekey = privatekey;
1717
this.apiHostname = API_HOSTNAME;
1818
this.settings = new Settings();
1919
this.sessionId = ('a-' + (Math.random() * 100000000)).substring(0, 10);
20-
this.personalizationToken = cookie.getCookie(PERSONALIZATION_TOKEN_COOKIE_NAME) || util.generateUUID();
20+
this.userTokenInPersonalization = cookie.getCookie(USER_TOKEN_COOKIE_NAME) || util.generateUUID();
2121

2222
/**
2323
* Fetch search results
@@ -205,23 +205,23 @@ var client = function(sitekey, privatekey) {
205205
this.setThrottleTime = function(delay) {this.settings.setThrottleTime(delay);}
206206
this.setStatsSessionId = function(id) {
207207
this.sessionId = id;
208-
this.personalizationToken = id;
208+
this.userTokenInPersonalization = null;
209209
}
210210
this.getStatsSessionId = function() {return this.sessionId;}
211211
this.enableLogicalOperators = function(enableLogicalOperators) {this.settings.enableLogicalOperators(enableLogicalOperators)};
212212
this.setSearchOperator = function(operator) {this.settings.setSearchOperator(operator)};
213213

214214
this.sendStatsEvent = function(type, keyword, data) {
215215

216-
var usePersonalizationToken = isPersonalizationTrackingEnabled && isAddSearchCookieConsented;
217-
if (usePersonalizationToken && !cookie.getCookie(PERSONALIZATION_TOKEN_COOKIE_NAME)) {
218-
cookie.setCookie(PERSONALIZATION_TOKEN_COOKIE_NAME, this.personalizationToken, personalizationCookieExpireDays);
216+
var useUserTokenInCookie = this.userTokenInPersonalization && isPersonalizationTrackingEnabled && isAddSearchCookieConsented;
217+
if (useUserTokenInCookie && !cookie.getCookie(USER_TOKEN_COOKIE_NAME)) {
218+
cookie.setCookie(USER_TOKEN_COOKIE_NAME, this.userTokenInPersonalization, personalizationCookieExpireDays);
219219
}
220220

221221
if (type === 'search') {
222222
let payload = {
223223
action: 'search',
224-
session: usePersonalizationToken ? this.personalizationToken : this.sessionId,
224+
session: useUserTokenInCookie ? this.userTokenInPersonalization : this.sessionId,
225225
keyword: keyword,
226226
numberOfResults: data.numberOfResults,
227227
analyticsTag: this.getSettings().analyticsTag
@@ -232,7 +232,7 @@ var client = function(sitekey, privatekey) {
232232
else if (type === 'click') {
233233
let payload = {
234234
action: 'click',
235-
session: usePersonalizationToken ? this.personalizationToken : this.sessionId,
235+
session: useUserTokenInCookie ? this.userTokenInPersonalization : this.sessionId,
236236
keyword: keyword,
237237
docid: data.documentId,
238238
position: data.position,
@@ -253,8 +253,8 @@ var client = function(sitekey, privatekey) {
253253
var isAddSearchCookieConsented = true;
254254
var personalizationCookieExpireDays = 180;
255255

256-
this.getPersonalizationToken = function() {
257-
return this.personalizationToken;
256+
this.getUserTokenInPersonalization = function() {
257+
return this.userTokenInPersonalization;
258258
};
259259

260260
this.enablePersonalizationTracking = function(isEnabled, cookieExpireDays) {

0 commit comments

Comments
 (0)