|
1322 | 1322 | }; |
1323 | 1323 | } |
1324 | 1324 | } |
1325 | | - |
| 1325 | + |
| 1326 | + /** |
| 1327 | + * Expires current session and starts a new session. |
| 1328 | + */ |
| 1329 | + function newSession() { |
| 1330 | + // If cookies are enabled, base visit count and session ID on the cookies |
| 1331 | + var nowTs = Math.round(new Date().getTime() / 1000), |
| 1332 | + ses = getSnowplowCookieValue('ses'), |
| 1333 | + id = loadDomainUserIdCookie(), |
| 1334 | + cookiesDisabled = id[0], |
| 1335 | + _domainUserId = id[1], // We could use the global (domainUserId) but this is better etiquette |
| 1336 | + createTs = id[2], |
| 1337 | + visitCount = id[3], |
| 1338 | + currentVisitTs = id[4], |
| 1339 | + lastVisitTs = id[5], |
| 1340 | + sessionIdFromCookie = id[6]; |
| 1341 | + |
| 1342 | + // When cookies are enabled |
| 1343 | + if (cookiesDisabled === '0') { |
| 1344 | + memorizedSessionId = sessionIdFromCookie; |
| 1345 | + |
| 1346 | + // When cookie/local storage is enabled - make a new session |
| 1347 | + if (configStateStorageStrategy != 'none') { |
| 1348 | + // New session (aka new visit) |
| 1349 | + visitCount++; |
| 1350 | + // Update the last visit timestamp |
| 1351 | + lastVisitTs = currentVisitTs; |
| 1352 | + // Regenerate the session ID |
| 1353 | + memorizedSessionId = uuid.v4(); |
| 1354 | + } |
| 1355 | + |
| 1356 | + memorizedVisitCount = visitCount; |
| 1357 | + |
| 1358 | + // Create a new session cookie |
| 1359 | + setSessionCookie() |
| 1360 | + |
| 1361 | + } else { |
| 1362 | + memorizedSessionId = uuid.v4(); |
| 1363 | + memorizedVisitCount++; |
| 1364 | + } |
| 1365 | + |
| 1366 | + // Update cookies |
| 1367 | + if (configStateStorageStrategy != 'none') { |
| 1368 | + setDomainUserIdCookie(_domainUserId, createTs, memorizedVisitCount, nowTs, |
| 1369 | + lastVisitTs, memorizedSessionId); |
| 1370 | + setSessionCookie(); |
| 1371 | + } |
| 1372 | + |
| 1373 | + lastEventTime = new Date().getTime(); |
| 1374 | + } |
| 1375 | + |
1326 | 1376 | /** |
1327 | 1377 | * Attempts to create a context using the geolocation API and add it to commonContexts |
1328 | 1378 | */ |
|
1612 | 1662 | return getPageViewId(); |
1613 | 1663 | }, |
1614 | 1664 |
|
| 1665 | + /** |
| 1666 | + * Expires current session and starts a new session. |
| 1667 | + */ |
| 1668 | + newSession: newSession, |
| 1669 | + |
1615 | 1670 | /** |
1616 | 1671 | * Get the cookie name as cookieNamePrefix + basename + . + domain. |
1617 | 1672 | * |
|
0 commit comments