Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asayerio/analytics.js-integration-asayer

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asayerio/analytics.js-integration-asayer - npm Package Compare versions

Comparing version 1.1.0 to 2.0.1

5

HISTORY.md

@@ -0,1 +1,6 @@

2.0.0 / 2020-05-13
==================
* New Asayer app
1.1.0 / 2019-06-30

@@ -2,0 +7,0 @@ ==================

0

karma.conf.ci.js

@@ -0,0 +0,0 @@ 'use strict'

@@ -0,0 +0,0 @@ 'use strict'

54

lib/index.js

@@ -7,20 +7,31 @@ 'use strict'

.global('asayer')
.option('siteId', null)
.tag('<script src="https://static.asayer.io/asayer.js" data-asayer-ns="asayer"></script>')
.option('projectId', null)
.option('obscureTextNumbers', false)
.option('obscureTextEmails', false)
.tag('<script src="https://static.asayer.io/tracker.js"></script>')
function positiveNumber (number) {
number = Number(number)
if (number === null || isNaN(number) || number === Infinity || number <= 0) {
return
}
return number
}
Asayer.prototype.initialize = function () {
var siteId = Number(this.options.siteId)
if (this.options.siteId === null || isNaN(siteId)) {
console.warn('Asayer wrong siteId option, not loading.')
var projectId = positiveNumber(this.options.projectId)
if (!projectId) {
console.warn('Asayer wrong projectId option, not loading.')
return
}
var r = [siteId]
var asayer = window.asayer = { r: r }
asayer.start = function (v) { r.push([0]) }
asayer.vars = function (k, v) { r.push([1, k, v]) }
asayer.event = function (t, p) { r.push([2, t, p]) }
asayer.id = Function.prototype
asayer.started = function () { return false }
var r = window.asayer = [projectId, undefined, 28 | (+this.options.obscureTextEmails) | (+this.options.obscureTextNumbers << 1), 0]
r.start = function (v) { r.push([0]) }
r.stop = function (v) { r.push([1]) }
r.userID = function (id) { r.push([2, id]) }
r.userAnonymousID = function (id) { r.push([3, id]) }
r.metadata = function (k, v) { r.push([4, k, v]) }
r.event = function (k, p) { r.push([5, k, p]) }
r.active = function () { return false }
r.sessionID = function () { }

@@ -31,24 +42,19 @@ this.load(this.ready)

Asayer.prototype.identify = function (identify) {
window.asayer.userAnonymousID(String(identify.anonymousId()))
if (identify.userId()) {
window.asayer.vars('userId', String(identify.userId()))
window.asayer.userID(String(identify.userId()))
}
var traits = identify.traits({
'anonymousId': 'anonymousId'
})
var traits = identify.traits()
for (var key in traits) {
if (traits.hasOwnProperty(key)) {
var value = traits[key]
if (value !== null && typeof value !== 'boolean' && typeof value !== 'string' && (typeof value !== 'number' || !isFinite(value))) {
delete traits[key]
if (typeof value !== 'object' && value !== undefined) {
window.asayer.metadata(key, value.toString())
}
}
}
window.asayer.vars(traits)
}
Asayer.prototype.track = function (track) {
var props = track.properties()
if (typeof props === 'object' && !Array.isArray(props)) {
window.asayer.event(track.event(), props)
}
window.asayer.event(track.event(), track.properties())
}
{
"name": "@asayerio/analytics.js-integration-asayer",
"description": "The Asayer analytics.js integration.",
"version": "1.1.0",
"version": "2.0.1",
"keywords": [

@@ -19,3 +19,3 @@ "analytics.js",

},
"author": "Alex Tsokurov <alex@asayer.io>",
"author": "Alex Tsokurov",
"license": "SEE LICENSE IN LICENSE",

@@ -22,0 +22,0 @@ "bugs": {

@@ -0,0 +0,0 @@ # analytics.js-integration-asayer [![Build Status][ci-badge]][ci-link]

@@ -26,3 +26,3 @@ 'use strict'

it('should call #load', function () {
asayer = new Asayer({ 'siteId': '1234' })
asayer = new Asayer({ 'projectId': '1234' })
analytics.use(Asayer)

@@ -35,4 +35,4 @@ analytics.add(asayer)

it('should not call #load for wrong siteId', function () {
asayer = new Asayer({ 'siteId': 'wrong' })
it('should not call #load for wrong projectId', function () {
asayer = new Asayer({ 'projectId': 'wrong' })
analytics.use(Asayer)

@@ -48,3 +48,3 @@ analytics.add(asayer)

beforeEach(function (done) {
asayer = new Asayer({ 'siteId': '1234' })
asayer = new Asayer({ 'projectId': '1234' })
analytics.use(Asayer)

@@ -57,22 +57,24 @@ analytics.add(asayer)

describe('#identify', function () {
beforeEach(function () {
analytics.stub(window.asayer, 'vars')
})
it('should send anonymousId', function () {
analytics.stub(window.asayer, 'userAnonymousID')
analytics.identify()
analytics.called(window.asayer.vars)
var vars = window.asayer.vars.args[0][0]
analytics.assert(vars && vars.anonymousId)
analytics.called(window.asayer.userAnonymousID)
var id = window.asayer.userAnonymousID.args[0][0]
analytics.assert(id && typeof id === 'string')
})
it('should send userId', function () {
analytics.stub(window.asayer, 'userID')
analytics.identify('1')
analytics.called(window.asayer.vars, 'userId', '1')
analytics.called(window.asayer.userID, '1')
})
it('should send only safe traits', function () {
analytics.identify('1', { 'email': 'hello@asayer.io', title: { hide: 'me' }, phone: true, custom: 'custom' })
var vars = window.asayer.vars.args[1][0]
analytics.assert(vars && vars.email === 'hello@asayer.io' && !vars.title && vars.phone && vars.custom === 'custom')
analytics.stub(window.asayer, 'metadata')
analytics.identify('1', { 'email': 'hello@asayer.io', title: { hide: 'me' }, admin: true })
var traits = {}
window.asayer.metadata.args.forEach(function (entry) {
traits[entry[0]] = entry[1]
})
analytics.assert(traits.email === 'hello@asayer.io' && !traits.title && traits.admin === 'true')
})

@@ -90,9 +92,4 @@ })

})
it('should not send non-object properties', function () {
analytics.track('segment', [1, 2, 3])
analytics.didNotCall(window.asayer.event)
})
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc