analytics-encryption
v0.0.2
Published
Config-based encryption for analytics in JavaScript
Downloads
5
Readme
Getting Started
Installation
Install with npm:
npm install --save analytics-encryption
Or with yarn:
yarn add analytics-encryption
Examples
import analyticsEncryption from 'analytics-encryption'
// Tries to find `window.analytics` and extend `.track/identify()`
const encryptedAnalytics = analyticsEncryption()
// Or you can pass in an analytics object
const analytics = analyticsEncryption({ analytics: trackingV1 })
Usage
Node.js
// ./analytics.js
import Analytics from 'analytics-node'
import EncryptionClient from '@ume/client'
import analyticsEncryption from 'analytics-encryption'
const apiHost = process.env.UME_API_HOST
const eclient = new EncryptionClient({ apiHost })
const originalAnalytics = new Analytics(process.env.WRITE_KEY)
const analytics = analyticsEncryption({
analytics: originalAnalytics,
local: { encrypt: eclient.encrypt.bind(eclient) }
})
const { track, identify } = analytics
export default analytics
export { track, identify }
// ./app.js
import { track } from './analytics'
track('Form Submitted', {
email: '[email protected]',
name: 'Example Name',
dob: '01-01-1999'
})
// turns into
originalAnalytics.track('Form Submitted', {
email: 'r8Udt6Swa+Znk7CI5+9W/0xQ7PckBj3+H983fun8LEAtLFnzvJzeuq',
name: 'ckBj3+H983ful8KUHuKglyawtfeKLVf4EAN3XEkKhmX',
dob: 'xt5crfiZhr5M7IPcbb2q8f8uB/Et77q'
})
Browser
// ./init.js
import EncryptionClient from '@ume/client'
import analyticsEncryption from 'analytics-encryption'
const apiHost = process.env.UME_API_HOST
const eclient = new EncryptionClient({ apiHost })
analyticsEncryption({
replace: true,
local: { encrypt: eclient.encrypt.bind(eclient) }
})
// ./app.js
window.analytics.track('Form Submitted', {
email: '[email protected]',
name: 'Example Name',
dob: '01-01-1999'
})
// turns into
window.analytics.original.track('Form Submitted', {
email: 'r8Udt6Swa+Znk7CI5+9W/0xQ7PckBj3+H983fun8LEAtLFnzvJzeuq',
name: 'ckBj3+H983ful8KUHuKglyawtfeKLVf4EAN3XEkKhmX',
dob: 'xt5crfiZhr5M7IPcbb2q8f8uB/Et77q'
})
Contributing
All contributions are welcome, analytics-encryption
is MIT-licensed.