Skip to content

Commit 9b9cf32

Browse files
committed
Script simplification: Final minor cleanups
1 parent 5369144 commit 9b9cf32

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/tracker/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const attr = currentScript.getAttribute.bind(currentScript);
2121
const website = attr(_data + 'website-id');
2222
const hostUrl = attr(_data + 'host-url');
23-
const tag = attr(_data + 'tag');
23+
const tag = attr(_data + 'tag') || undefined;
2424
const autoTrack = attr(_data + 'auto-track') !== _false;
2525
const dnt = attr(_data + 'do-not-track') === _true;
2626
const excludeSearch = attr(_data + 'exclude-search') === _true;
@@ -45,7 +45,7 @@
4545
hostname,
4646
url: currentUrl,
4747
referrer: currentRef,
48-
tag: tag ? tag : undefined,
48+
tag,
4949
});
5050

5151
const hasDoNotTrack = () => {
@@ -73,10 +73,8 @@
7373
const handlePathChanges = () => {
7474
const hook = (_this, method, callback) => {
7575
const orig = _this[method];
76-
7776
return (...args) => {
7877
callback.apply(null, args);
79-
8078
return orig.apply(_this, args);
8179
};
8280
};
@@ -87,14 +85,13 @@
8785

8886
const handleClicks = () => {
8987
const trackElement = async el => {
90-
const attr = el.getAttribute.bind(el);
91-
const eventName = attr(eventNameAttribute);
88+
const eventName = el.getAttribute(eventNameAttribute);
9289
if (eventName) {
9390
const eventData = {};
9491

9592
el.getAttributeNames().forEach(name => {
9693
const match = name.match(eventRegex);
97-
if (match) eventData[match[1]] = attr(name);
94+
if (match) eventData[match[1]] = el.getAttribute(name);
9895
});
9996

10097
return track(eventName, eventData);
@@ -106,8 +103,7 @@
106103
if (!parentElement) return trackElement(el);
107104

108105
const { href, target } = parentElement;
109-
const eventName = parentElement.getAttribute(eventNameAttribute);
110-
if (!eventName) return;
106+
if (!parentElement.getAttribute(eventNameAttribute)) return;
111107

112108
if (parentElement.tagName === 'BUTTON') {
113109
return trackElement(parentElement);
@@ -158,7 +154,7 @@
158154
cache = data.cache;
159155
}
160156
} catch (e) {
161-
/* empty */
157+
/* no-op */
162158
}
163159
};
164160

0 commit comments

Comments
 (0)