confusingstraw commented on a change in pull request #64:
URL:
https://github.com/apache/incubator-flagon-useralejs/pull/64#discussion_r597154184
##########
File path: example/log-label-example/README.md
##########
@@ -0,0 +1,97 @@
+# Custom Log Label Examples
+
+Examples illustrating how to add custom labels to logs generated by `userale`.
+
+## Adding Custom Labels to Logs
+
+### Method 1
+
+Consider the following HTML:
+
+```html
+
+<div>
+ <button>New Feature</button>
+</div>
+```
+
+The following code snippet will add a custom field and send a log whenever the
new feature button is clicked:
+
+```js
+document.addEventListener('click', function (e) {
+ if (e.target.innerHTML === 'New Feature') {
+ window.userale.map(log => ({...log, logType: 'custom', customLabel:
'New Feature'}));
+ window.userale.packageLog(e,
window.userale.details(window.userale.options(), e.type));
+ window.userale.map();
+ } else {
+ return false
+ }
+});
Review comment:
if you want to make the code extra compact (not something i am a huge
fan of), you can write it like this:
```js
window.userale.map((log, e) => e.target.innerHTML === 'New Feature'
? { ...log, customLabel: 'New Feature', logType: 'custom' }
: log);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]