react-redux-analytics-td
Advanced tools
Comparing version 0.0.1-beta7 to 0.0.1-beta8
@@ -9,2 +9,4 @@ 'use strict'; | ||
var debugNamespace = exports.debugNamespace = namespace + ':debug'; | ||
var errorNamespace = exports.errorNamespace = namespace + ':error'; | ||
var errorNamespace = exports.errorNamespace = namespace + ':error'; | ||
var TYPE_EVENT = exports.TYPE_EVENT = 'event'; | ||
var TYPE_PAGEVIEW = exports.TYPE_PAGEVIEW = 'pageview'; |
@@ -21,4 +21,2 @@ 'use strict'; | ||
var _const = require('./const'); | ||
var _defaultConfig = require('./default.config.js'); | ||
@@ -30,2 +28,4 @@ | ||
var _const = require('./const'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -142,5 +142,5 @@ | ||
} | ||
var composedVars = this.composeVariables({ variables: variables, type: 'pageview' }); | ||
var composedVars = this.composeVariables({ variables: variables, type: _const.TYPE_PAGEVIEW }); | ||
try { | ||
await this.track('pageview', composedVars); | ||
await this.track(_const.TYPE_PAGEVIEW, composedVars); | ||
debug((this.config.dryRun ? '(dry-run)' : '(tracked)') + ' pageview: ' + JSON.stringify(composedVars)); | ||
@@ -158,5 +158,5 @@ } catch (e) { | ||
var composedVars = this.composeVariables({ variables: variables, eventName: eventName, type: 'event' }); | ||
var composedVars = this.composeVariables({ variables: variables, eventName: eventName, type: _const.TYPE_EVENT }); | ||
try { | ||
await this.track('event', composedVars); | ||
await this.track(_const.TYPE_EVENT, composedVars); | ||
debug((this.config.dryRun ? '(dry-run)' : '(tracked)') + ' event(' + eventName + '): ' + JSON.stringify(composedVars)); | ||
@@ -178,3 +178,6 @@ } catch (e) { | ||
} | ||
var table = type === 'pageview' ? _this.config.pageViewTable : _this.config.eventTable; | ||
var table = _this.getTableName(type); | ||
if (!table) { | ||
reject('Table name must be supplied.'); | ||
} | ||
var successCallback = function successCallback(ret) { | ||
@@ -197,2 +200,16 @@ resolve(ret); | ||
}, { | ||
key: 'getTableName', | ||
value: function getTableName(type) { | ||
if (type === _const.TYPE_PAGEVIEW) { | ||
return this.config.pageViewTable; | ||
} | ||
if (type === _const.TYPE_EVENT) { | ||
return this.config.eventTable; | ||
} | ||
return null; | ||
} | ||
//protected: | ||
}, { | ||
key: 'composeVariables', | ||
@@ -206,8 +223,10 @@ value: function composeVariables(_ref6) { | ||
composed[this.config.trackTypeKey] = type; | ||
if (this.config.sendReferrer) { | ||
composed[this.config.referrerKey] = this.composeLocation(this.location.referrer); | ||
if (event === _const.TYPE_PAGEVIEW) { | ||
if (this.config.sendReferrer) { | ||
composed[this.config.referrerKey] = this.composeLocation(this.location.referrer); | ||
} | ||
if (this.config.sendLocation) { | ||
composed[this.config.locationKey] = this.composeLocation(this.location.current); | ||
} | ||
} | ||
if (this.config.sendLocation) { | ||
composed[this.config.locationKey] = this.composeLocation(this.location.current); | ||
} | ||
if (eventName) { | ||
@@ -214,0 +233,0 @@ composed[this.config.eventNameKey] = eventName; |
{ | ||
"name": "react-redux-analytics-td", | ||
"version": "0.0.1-beta7", | ||
"version": "0.0.1-beta8", | ||
"description": "TreasureData plugin for react-redux-analytics", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
export const configKeyTd = 'td' | ||
const namespace = 'analytics-td' | ||
export const debugNamespace = namespace+':debug' | ||
export const errorNamespace = namespace+':error' | ||
export const errorNamespace = namespace+':error' | ||
export const TYPE_EVENT = 'event' | ||
export const TYPE_PAGEVIEW = 'pageview' |
import debugFactory from 'debug' | ||
import isBrowser from 'is-in-browser'; | ||
import { pickBy } from 'lodash/fp' | ||
import { configKeyTd, debugNamespace, errorNamespace } from './const' | ||
import defaultConfig from './default.config.js' | ||
import { composeLocationString } from './utils' | ||
import { | ||
configKeyTd, | ||
debugNamespace, | ||
errorNamespace, | ||
TYPE_EVENT, | ||
TYPE_PAGEVIEW, | ||
} from './const' | ||
@@ -91,5 +97,5 @@ const debug = debugFactory(debugNamespace) | ||
} | ||
const composedVars = this.composeVariables({ variables, type: 'pageview' }) | ||
const composedVars = this.composeVariables({ variables, type: TYPE_PAGEVIEW}) | ||
try { | ||
await this.track('pageview', composedVars) | ||
await this.track(TYPE_PAGEVIEW, composedVars) | ||
debug(`${this.config.dryRun ? '(dry-run)': '(tracked)'} pageview: ${JSON.stringify(composedVars)}`) | ||
@@ -103,5 +109,5 @@ }catch(e){ | ||
async sendEvent({ variables, eventName }){ | ||
const composedVars = this.composeVariables({ variables, eventName, type: 'event' }) | ||
const composedVars = this.composeVariables({ variables, eventName, type: TYPE_EVENT }) | ||
try{ | ||
await this.track('event', composedVars) | ||
await this.track(TYPE_EVENT, composedVars) | ||
debug(`${this.config.dryRun ? '(dry-run)': '(tracked)'} event(${eventName}): ${JSON.stringify(composedVars)}`) | ||
@@ -113,3 +119,3 @@ }catch(e){ | ||
} | ||
async track(type, variables){ | ||
@@ -121,3 +127,6 @@ return new Promise((resolve, reject) => { | ||
} | ||
const table = type === 'pageview' ? this.config.pageViewTable : this.config.eventTable | ||
const table = this.getTableName(type) | ||
if(!table){ | ||
reject('Table name must be supplied.') | ||
} | ||
const successCallback = (ret) => { | ||
@@ -138,11 +147,24 @@ resolve(ret) | ||
//protected: | ||
getTableName(type){ | ||
if(type === TYPE_PAGEVIEW){ | ||
return this.config.pageViewTable | ||
} | ||
if(type === TYPE_EVENT){ | ||
return this.config.eventTable | ||
} | ||
return null | ||
} | ||
//protected: | ||
composeVariables({ variables, eventName, type }) { | ||
const composed = { ...variables } | ||
composed[this.config.trackTypeKey] = type | ||
if(this.config.sendReferrer){ | ||
composed[this.config.referrerKey] = this.composeLocation(this.location.referrer) | ||
if(event === TYPE_PAGEVIEW){ | ||
if(this.config.sendReferrer){ | ||
composed[this.config.referrerKey] = this.composeLocation(this.location.referrer) | ||
} | ||
if(this.config.sendLocation){ | ||
composed[this.config.locationKey] = this.composeLocation(this.location.current) | ||
} | ||
} | ||
if(this.config.sendLocation){ | ||
composed[this.config.locationKey] = this.composeLocation(this.location.current) | ||
} | ||
if(eventName){ | ||
@@ -149,0 +171,0 @@ composed[this.config.eventNameKey] = eventName |
28507
687