@cmpsr/analytics
Advanced tools
Comparing version 0.0.18 to 0.0.19
# Change Log | ||
## 0.0.19 | ||
### Patch Changes | ||
- 5f9a803: Add babel plugin to compile class properties | ||
## 0.0.18 | ||
@@ -4,0 +10,0 @@ |
@@ -10,4 +10,31 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
class GA { | ||
constructor(config) { | ||
_defineProperty(this, "identify", userId => { | ||
window.ga('set', 'userId', userId); | ||
window.ga('send', 'event', 'authentication', 'user-id available'); | ||
}); | ||
_defineProperty(this, "group", () => {}); | ||
_defineProperty(this, "page", (pageName, traits = {}) => { | ||
window.ga('send', { | ||
hitType: 'pageview', | ||
page: traits.path || location.pathname, | ||
title: pageName | ||
}); | ||
}); | ||
_defineProperty(this, "track", (eventName, traits = {}) => { | ||
window.ga('send', { | ||
hitType: 'event', | ||
eventCategory: traits.category || 'None', | ||
eventAction: eventName | ||
}); | ||
}); | ||
_defineProperty(this, "reset", () => {}); | ||
if (!config.trackingId) { | ||
@@ -21,28 +48,4 @@ throw new Error('Segment writeKey is required for analytics'); | ||
identify = userId => { | ||
window.ga('set', 'userId', userId); | ||
window.ga('send', 'event', 'authentication', 'user-id available'); | ||
}; // Not supported | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
group = () => {}; | ||
page = (pageName, traits = {}) => { | ||
window.ga('send', { | ||
hitType: 'pageview', | ||
page: traits.path || location.pathname, | ||
title: pageName | ||
}); | ||
}; | ||
track = (eventName, traits = {}) => { | ||
window.ga('send', { | ||
hitType: 'event', | ||
eventCategory: traits.category || 'None', | ||
eventAction: eventName | ||
}); | ||
}; // Not supported | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
reset = () => {}; | ||
} | ||
exports.GA = GA; |
@@ -14,4 +14,35 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
class Segment { | ||
constructor(config) { | ||
_defineProperty(this, "identify", (userId, traits) => { | ||
window.analytics(userId, traits); | ||
}); | ||
_defineProperty(this, "group", (groupId, traits) => { | ||
window.analytics.group(groupId, traits); | ||
}); | ||
_defineProperty(this, "page", (pageName, traits = {}) => { | ||
const { | ||
category | ||
} = traits, | ||
rest = _objectWithoutProperties(traits, ["category"]); | ||
if (category) { | ||
window.analytics.page(category, pageName, rest); | ||
} else { | ||
window.analytics.page(pageName, rest); | ||
} | ||
}); | ||
_defineProperty(this, "track", (eventName, traits) => { | ||
window.analytics.track(eventName, traits); | ||
}); | ||
_defineProperty(this, "reset", () => { | ||
window.analytics.reset(); | ||
}); | ||
if (!config.writeKey) { | ||
@@ -25,28 +56,4 @@ throw new Error('Segment writeKey is required for analytics'); | ||
identify = (userId, traits) => { | ||
window.analytics(userId, traits); | ||
}; | ||
group = (groupId, traits) => { | ||
window.analytics.group(groupId, traits); | ||
}; | ||
page = (pageName, traits = {}) => { | ||
const { | ||
category | ||
} = traits, | ||
rest = _objectWithoutProperties(traits, ["category"]); | ||
if (category) { | ||
window.analytics.page(category, pageName, rest); | ||
} else { | ||
window.analytics.page(pageName, rest); | ||
} | ||
}; | ||
track = (eventName, traits) => { | ||
window.analytics.track(eventName, traits); | ||
}; | ||
reset = () => { | ||
window.analytics.reset(); | ||
}; | ||
} | ||
exports.Segment = Segment; |
@@ -10,3 +10,3 @@ { | ||
}, | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"author": "Steve Cox <stevejcox@me.com>", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"scripts": { | ||
"libbuild": "rimraf lib && babel src --out-dir lib --extensions '.ts,.tsx' --copy-files && tsc -d --declarationDir lib --declarationMap --emitDeclarationOnly", | ||
"libbuild": "rimraf lib && babel src --out-dir lib --extensions '.ts,.tsx' --copy-files && find lib -type f -name '*.test.*' -exec rm {} + && tsc -d --declarationDir lib --declarationMap --emitDeclarationOnly", | ||
"test": "jest", | ||
@@ -28,5 +28,6 @@ "test:watch": "jest --watch", | ||
"devDependencies": { | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@types/js-cookie": "^2.2.5" | ||
}, | ||
"gitHead": "77b0642b0291559e2897fa73d599acf8b0204d69" | ||
"gitHead": "c6a0569a7de0f05e755c2f2a124b237b350913eb" | ||
} |
Sorry, the diff of this file is not supported yet
45781
2
70
988