Skip to content

Commit

Permalink
Merge pull request #21 from CleverTap/develop
Browse files Browse the repository at this point in the history
Exposed option to set logger and fixed the double parsing to local storage
  • Loading branch information
Victor Fernandes authored Feb 17, 2021
2 parents 04dd24c + 9147bce commit 6ffbd02
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ dist


.DS_Store
clevertap.min.js
clevertap.min.js
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ clevertap.profile.push({
})
```

### Debugging

This section is applicable for all browsers such as, Chrome, Firefox, and Safari. Error messages and warnings are logged to the JS console of the browser.

For verbose logging, enable verbose logging of all communication with the CleverTap servers by setting the ```WZRK_D``` variable in sessionStorage. In the developer console of your browser type, ```sessionStorage['WZRK_D'] = '';```

Alternatively, you can also set the log levels after calling ```clevertap.init()``` in the following way:

```javascript
clevertap.setLogLevel(LOG_LEVEL)
// Here Log Levels is an integer that can be any of the folowing:
// 0: disable all logs
// 1: display only errors
// 2: display errors and info
// 3: display all logs
```


## 𝌡 Example Usage
* A [react application](https://github.com/CleverTap/clevertap-web-sdk/tree/master/example-apps/react) showing the integration of our SDK in a create react app project.
* An [angular application](https://github.com/CleverTap/clevertap-web-sdk/tree/master/example-apps/angular) showing the integration of our SDK in an Angular CLI generated project.
Expand Down
12 changes: 10 additions & 2 deletions clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
}

if (this._isLocalStorageSupported()) {
localStorage.setItem(key, JSON.stringify(value));
localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value));
return true;
}
}
Expand Down Expand Up @@ -574,7 +574,11 @@
if (property === GCOOKIE_NAME) {
value = decodeURIComponent(data);
} else {
value = JSON.parse(decodeURIComponent(data));
try {
value = JSON.parse(decodeURIComponent(data));
} catch (err) {
value = decodeURIComponent(data);
}
}

$ct.globalCache[property] = value;
Expand Down Expand Up @@ -4831,6 +4835,10 @@
return _classPrivateFieldLooseBase(_this, _device$3)[_device$3].getGuid();
};

this.setLogLevel = function (l) {
_classPrivateFieldLooseBase(_this, _logger$8)[_logger$8].logLevel = Number(l);
};

var _handleEmailSubscription = function _handleEmailSubscription(subscription, reEncoded, fetchGroups) {
handleEmailSubscription(subscription, reEncoded, fetchGroups, _classPrivateFieldLooseBase(_this, _account$5)[_account$5]);
};
Expand Down
2 changes: 1 addition & 1 deletion clevertap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clevertap-web-sdk",
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.5",
"description": "",
"main": "clevertap.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/clevertap.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export default class CleverTap {
return this.#device.getGuid()
}

this.setLogLevel = (l) => {
this.#logger.logLevel = Number(l)
}

const _handleEmailSubscription = (subscription, reEncoded, fetchGroups) => {
handleEmailSubscription(subscription, reEncoded, fetchGroups, this.#account)
}
Expand Down
8 changes: 6 additions & 2 deletions src/util/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StorageManager {
return false
}
if (this._isLocalStorageSupported()) {
localStorage.setItem(key, JSON.stringify(value))
localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value))
return true
}
}
Expand Down Expand Up @@ -123,7 +123,11 @@ export class StorageManager {
if (property === GCOOKIE_NAME) {
value = decodeURIComponent(data)
} else {
value = JSON.parse(decodeURIComponent(data))
try {
value = JSON.parse(decodeURIComponent(data))
} catch (err) {
value = decodeURIComponent(data)
}
}
$ct.globalCache[property] = value
return value
Expand Down

0 comments on commit 6ffbd02

Please sign in to comment.