Skip to content
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"sane": "^4.1.0",
"sync-rpc": "^1.3.6",
"terser": "^5.10.0",
"tsd-jsdoc": "^2.5.0",
"typescript": "^4.3.5",
"uglify-js": "^3.15.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"main": "dist/server/analytics-core.js",
"module": "dist/server/analytics-core.module.js",
"unpkg": "dist/server/analytics-core.umd.js",
"types": "dist/types.d.ts",
"types": "dist/index.d.ts",
"browser": {
"./dist/server/analytics-core.js": "./dist/client/analytics-core.js",
"./dist/server/analytics-core.umd.js": "./dist/client/analytics-core.umd.js",
Expand All @@ -32,11 +32,11 @@
"scripts": {
"test": "ava -v",
"test:watch": "ava -v --watch",
"prebuild": "rimraf dist _temp-types",
"prebuild": "rimraf dist",
"build": "npm run build-client && npm run build-server && npm run types",
"build-client": "cd client && npm run build",
"build-server": "cd server && npm run build",
"types": "../../node_modules/.bin/jsdoc -t ../../node_modules/tsd-jsdoc/dist -r ./src/ -d _temp-types && node scripts/types.js",
"types": "tsc",
"publish": "git push origin && git push origin --tags",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
Expand Down
85 changes: 0 additions & 85 deletions packages/analytics-core/scripts/types.js

This file was deleted.

13 changes: 5 additions & 8 deletions packages/analytics-core/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
/**
* Core Analytic constants. These are exposed for third party plugins & listeners
* @typedef {Object} constants
* @property {ANON_ID} ANON_ID - Anonymous visitor Id localstorage key
* @property {USER_ID} USER_ID - Visitor Id localstorage key
* @property {USER_TRAITS} USER_TRAITS - Visitor traits localstorage key
*/
import { PREFIX } from '@analytics/type-utils'


/**
* Anonymous visitor Id localstorage key
* @typedef {String} ANON_ID
* @type {string}
*/
export const ANON_ID = PREFIX + 'anon_id' // __anon_id

/**
* Visitor Id localstorage key
* @typedef {String} USER_ID
* @type {string}
*/
export const USER_ID = PREFIX + 'user_id' // __user_id

/**
* Visitor traits localstorage key
* @typedef {String} USER_TRAITS
* @type {string}
*/
export const USER_TRAITS = PREFIX + 'user_traits' // __user_traits
64 changes: 20 additions & 44 deletions packages/analytics-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ import { Debug, composeWithDebug } from './utils/debug'
import heartBeat from './utils/heartbeat'
import ensureArray from './utils/ensureArray'
import enrichMeta from './utils/enrichMeta'
import './pluginTypeDef'
import './types'


/**
* Analytics library configuration
*
* After the library is initialized with config, the core API is exposed & ready for use in the application.
*
* @param {object} config - analytics core config
* @param {string} [config.app] - Name of site / app
* @param {string|number} [config.version] - Version of your app
* @param {boolean} [config.debug] - Should analytics run in debug mode
* @param {Array.<AnalyticsPlugin>} [config.plugins] - Array of analytics plugins
* @return {AnalyticsInstance} Analytics Instance
* @param {AnalyticsInstanceConfig} [config={}] - analytics core config
* @returns {AnalyticsInstance} Analytics Instance
* @example
*
* import Analytics from 'analytics'
Expand Down Expand Up @@ -179,9 +175,6 @@ function analytics(config = {}) {
* Async Management methods for plugins.
*
* This is also where [custom methods](https://bit.ly/329vFXy) are loaded into the instance.
* @typedef {Object} Plugins
* @property {EnablePlugin} enable - Set storage value
* @property {DisablePlugin} disable - Remove storage value
* @example
*
* // Enable a plugin by namespace
Expand All @@ -193,10 +186,9 @@ function analytics(config = {}) {
const plugins = {
/**
* Enable analytics plugin
* @typedef {Function} EnablePlugin
* @param {string|string[]} plugins - name of plugins(s) to disable
* @param {Function} [callback] - callback after enable runs
* @returns {Promise}
* @param {string|string[]} plugins - name of plugins(s) to enable
* @param {Callback} [callback] - callback after enable runs
* @returns {Promise<void>}
* @example
*
* analytics.plugins.enable('google-analytics').then(() => {
Expand All @@ -219,10 +211,9 @@ function analytics(config = {}) {
},
/**
* Disable analytics plugin
* @typedef {Function} DisablePlugin
* @param {string|string[]} plugins - name of integration(s) to disable
* @param {Function} [callback] - callback after disable runs
* @returns {Promise}
* @param {string|string[]} plugins - name of integration(s) to disable
* @param {Callback} [callback] - callback after disable runs
* @returns {Promise<void>}
* @example
*
* analytics.plugins.disable('google').then(() => {
Expand Down Expand Up @@ -278,29 +269,16 @@ function analytics(config = {}) {
let readyCalled = false
/**
* Analytic instance returned from initialization
* @typedef {Object} AnalyticsInstance
* @property {Identify} identify - Identify a user
* @property {Track} track - Track an analytics event
* @property {Page} page - Trigger page view
* @property {User} user - Get user data
* @property {Reset} reset - Clear information about user & reset analytics
* @property {Ready} ready - Fire callback on analytics ready event
* @property {On} on - Fire callback on analytics lifecycle events.
* @property {Once} once - Fire callback on analytics lifecycle events once.
* @property {GetState} getState - Get data about user, activity, or context.
* @property {Storage} storage - storage methods
* @property {Plugins} plugins - plugin methods
* @type {AnalyticsInstance}
*/
const instance = {
/**
* Identify a user. This will trigger `identify` calls in any installed plugins and will set user data in localStorage
* @typedef {Function} Identify
* @param {String} userId - Unique ID of user
* @param {Object} [traits] - Object of user traits
* @param {Object} [options] - Options to pass to identify call
* @param {Function} [callback] - Callback function after identify completes
* @returns {Promise}
* @api public
* @param {string|Object} [userId] - Unique ID of user or traits object
* @param {Object} [traits] - Object of user traits
* @param {Object} [options] - Options to pass to identify call
* @param {Callback} [callback] - Callback function after identify completes
* @returns {Promise<void>}
*
* @example
*
Expand Down Expand Up @@ -360,13 +338,11 @@ function analytics(config = {}) {
},
/**
* Track an analytics event. This will trigger `track` calls in any installed plugins
* @typedef {Function} Track
* @param {String} eventName - Event name
* @param {Object} [payload] - Event payload
* @param {Object} [options] - Event options
* @param {Function} [callback] - Callback to fire after tracking completes
* @returns {Promise}
* @api public
* @param {string} eventName - Event name
* @param {Object} [payload] - Event payload
* @param {Object} [options] - Event options
* @param {Callback} [callback] - Callback to fire after tracking completes
* @returns {Promise<void>}
*
* @example
*
Expand Down
16 changes: 4 additions & 12 deletions packages/analytics-core/src/modules/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ function currentUrl(search) {
}

/**
* Page data for overides
* @typedef {object} PageData
* @property {string} [title] - Page title
* @property {string} [url] - Page url
* @property {string} [path] - Page path
* @property {string} [search] - Page search
* @property {string} [width] - Page width
* @property {string} [height] - Page height
*/
* Page data for overrides
*/

/**
* Get information about current page
* @typedef {Function} getPageData
* @param {PageData} [pageData = {}] - Page data overides
* @return {PageData} resolved page data
* @param {PageData} [pageData={}] - Page data overrides
* @returns {PageData} resolved page data
*/
export const getPageData = (pageData = {}) => {
if (!isBrowser) return pageData
Expand Down
12 changes: 0 additions & 12 deletions packages/analytics-core/src/pluginTypeDef.js

This file was deleted.

Loading