From c920884bb66399b1a55c68574a9702be9da5c0ef Mon Sep 17 00:00:00 2001
From: Bilal Mir <bilalmir135@gmail.com>
Date: Fri, 5 May 2023 18:57:07 +0500
Subject: [PATCH] fix(cookie): conset handling and distinctId key (#35)

---
 CHANGELOG.md               | 7 +++++++
 package.json               | 2 +-
 src/BaseAnalytics/index.js | 2 +-
 src/UserInfo/index.js      | 4 ++--
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 530aaf9..10d1f77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -121,3 +121,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 
 - Make gelocation tracking optional.
+
+## [1.0.0-beta.2] - 2023-05-05
+
+### Fixed
+
+- Cookie handling with consent.
+- DistinctId key bug.
diff --git a/package.json b/package.json
index 5a6b505..0a499a2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "analytics-web3",
-  "version": "1.0.0-beta.1",
+  "version": "1.0.0-beta.2",
   "description": "Spock analytics SDK analytics-web3 is a js module to collect and log all the data and events of DApp for analytics.",
   "main": "dist/analytics-web3.min.js",
   "license": "UNLICENSED",
diff --git a/src/BaseAnalytics/index.js b/src/BaseAnalytics/index.js
index 574b5c5..53b9836 100644
--- a/src/BaseAnalytics/index.js
+++ b/src/BaseAnalytics/index.js
@@ -45,7 +45,7 @@ class BaseAnalytics {
   }
 
   setConsetCookie(cName, cValue, expiry) {
-    this.store.optOut && setCookie(cName, cValue, expiry);
+    !this.store.optOut && setCookie(cName, cValue, expiry);
   }
 
   trackEvent({ event, properties, logMessage, callback }) {
diff --git a/src/UserInfo/index.js b/src/UserInfo/index.js
index a9505f3..e5e822d 100644
--- a/src/UserInfo/index.js
+++ b/src/UserInfo/index.js
@@ -209,14 +209,14 @@ class UserInfo extends BaseAnalytics {
   }
 
   distinctId(userAgent) {
-    const cachedDistinctId = getCookie(STORAGE.COOKIES.CACHE_DISTINCT_ID);
+    const cachedDistinctId = getCookie(STORAGE.COOKIES.DISTINCT_ID);
     if (notUndefined(cachedDistinctId)) {
       return cachedDistinctId;
     }
 
     const newDistinctId = this.uuid(userAgent);
     const ONE_YEAR = 365 * 24 * 60 * 60 * 1000;
-    this.setConsetCookie(STORAGE.COOKIES.CACHE_DISTINCT_ID, newDistinctId, ONE_YEAR);
+    this.setConsetCookie(STORAGE.COOKIES.DISTINCT_ID, newDistinctId, ONE_YEAR);
     return newDistinctId;
   }