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

@analytics/amplitude

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@analytics/amplitude - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [0.1.0](https://github.com/DavidWells/analytics/compare/@analytics/amplitude@0.0.4...@analytics/amplitude@0.1.0) (2021-10-24)
### Features
* add support for session Id in amplitude [#203](https://github.com/DavidWells/analytics/issues/203) ([86b797b](https://github.com/DavidWells/analytics/commit/86b797b))
## [0.0.4](https://github.com/DavidWells/analytics/compare/@analytics/amplitude@0.0.3...@analytics/amplitude@0.0.4) (2021-10-23)

@@ -8,0 +19,0 @@

32

dist/@analytics/amplitude.js

@@ -37,2 +37,3 @@ var analyticsAmplitude = (function () {

var apiKey = config.apiKey,
initialSessionId = config.initialSessionId,
customScriptSrc = config.customScriptSrc,

@@ -150,3 +151,9 @@ _config$integritySha = config.integritySha,

window.amplitude.init(config.apiKey, null, options, initComplete);
window.amplitude.init(config.apiKey, null, options, initComplete); // Set initial session id. Ref https://bit.ly/3vElAym
if (initialSessionId) {
setTimeout(function () {
return setSessionId(initialSessionId);
}, 10);
}
},

@@ -181,6 +188,29 @@ page: function page(_ref2) {

return amplitudeInitCompleted;
},
// https://getanalytics.io/plugins/writing-plugins/#adding-custom-methods
methods: {
/**
* analytics.plugins['amplitude'].setSessionId('your-id')
*/
setSessionId: setSessionId
}
};
}
/**
* Set Amplitude session ID. Ref https://bit.ly/3vElAym
* @param {string} sessionId - Minimum visit length before first page ping event fires
*/
function setSessionId(sessionId) {
if (typeof window.amplitude === 'undefined') {
console.log('Amplitude not loaded yet');
return false;
}
var amplitudeInstance = window.amplitude.getInstance();
amplitudeInstance.setSessionId(sessionId);
amplitudeInstance.enableTracking();
}
/* This module will shake out unused code + work in browser and node 🎉 */

@@ -187,0 +217,0 @@

2

dist/@analytics/amplitude.min.js

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

var analyticsAmplitude=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=null,o=!1,i=function(e){n=e,o=!0};return{name:"amplitude",config:t,initialize:function(t){var n=t.config,o=n.apiKey,r=n.customScriptSrc,s=n.integritySha,a=void 0===s?"":s,u=n.options,c=void 0===u?{}:u;if(!o)throw new Error("Amplitude project API key is not defined");if(c&&"object"!==e(c))throw new Error("Amplitude SDK options must be an object");if(void 0===window.amplitude){var p=r||"https://cdn.amplitude.com/libs/amplitude-8.1.0-min.gz.js",l=a||"sha384-u0hlTAJ1tNefeBKwiBNwB4CkHZ1ck4ajx/pKmwWtc+IufKJiCQZ+WjJIi+7C6Ntm"(function(e,t){var n=e.amplitude||{_q:[],_iq:{}},o=t.createElement("script");o.type="text/javascript",l&&(o.integrity=l),o.crossOrigin="anonymous",o.async=!0,o.src=p,o.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var i=t.getElementsByTagName("script")[0];function r(e,t){e.prototype[t]=function(){return this._q.push([t].concat(Array.prototype.slice.call(arguments,0))),this}}i.parentNode.insertBefore(o,i);for(var s=function(){return this._q=[],this},a=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"],u=0;u<a.length;u++)r(s,a[u]);n.Identify=s;for(var c=function(){return this._q=[],this},d=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"],f=0;f<d.length;f++)r(c,d[f]);n.Revenue=c;var y=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"];function m(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}for(var n=0;n<y.length;n++)t(y[n])}m(n),n.getInstance=function(e){return e=(e&&0!==e.length?e:"$default_instance").toLowerCase(),Object.prototype.hasOwnProperty.call(n._iq,e)||(n._iq[e]={_q:[]},m(n._iq[e])),n._iq[e]},e.amplitude=n})(window,document);window.amplitude.init(n.apiKey,null,c,i)}},page:function(e){var t=e.payload,o=t.properties,i=t.options,r="Page View";i&&i.eventType&&(r=i.eventType),n.logEvent(r,o)},track:function(e){var t=e.payload,o=t.event,i=t.properties;n.logEvent(o,i)},identify:function(e){var t=e.payload,o=t.userId,i=t.traits;e.instance,n.setUserId(o),n.setUserProperties(i)},loaded:function(){return o}}}}();
var analyticsAmplitude=function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e){if(void 0===window.amplitude)return console.log("Amplitude not loaded yet"),!1;var t=window.amplitude.getInstance();t.setSessionId(e),t.enableTracking()}return function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=null,o=!1,r=function(e){i=e,o=!0};return{name:"amplitude",config:n,initialize:function(n){var i=n.config,o=i.apiKey,s=i.initialSessionId,a=i.customScriptSrc,u=i.integritySha,c=void 0===u?"":u,l=i.options,p=void 0===l?{}:l;if(!o)throw new Error("Amplitude project API key is not defined");if(p&&"object"!==e(p))throw new Error("Amplitude SDK options must be an object");if(void 0===window.amplitude){var d=a||"https://cdn.amplitude.com/libs/amplitude-8.1.0-min.gz.js",f=c||"sha384-u0hlTAJ1tNefeBKwiBNwB4CkHZ1ck4ajx/pKmwWtc+IufKJiCQZ+WjJIi+7C6Ntm"(function(e,t){var n=e.amplitude||{_q:[],_iq:{}},i=t.createElement("script");i.type="text/javascript",f&&(i.integrity=f),i.crossOrigin="anonymous",i.async=!0,i.src=d,i.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var o=t.getElementsByTagName("script")[0];function r(e,t){e.prototype[t]=function(){return this._q.push([t].concat(Array.prototype.slice.call(arguments,0))),this}}o.parentNode.insertBefore(i,o);for(var s=function(){return this._q=[],this},a=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"],u=0;u<a.length;u++)r(s,a[u]);n.Identify=s;for(var c=function(){return this._q=[],this},l=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"],p=0;p<l.length;p++)r(c,l[p]);n.Revenue=c;var y=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"];function m(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}for(var n=0;n<y.length;n++)t(y[n])}m(n),n.getInstance=function(e){return e=(e&&0!==e.length?e:"$default_instance").toLowerCase(),Object.prototype.hasOwnProperty.call(n._iq,e)||(n._iq[e]={_q:[]},m(n._iq[e])),n._iq[e]},e.amplitude=n})(window,document);window.amplitude.init(i.apiKey,null,p,r),s&&setTimeout(function(){return t(s)},10)}},page:function(e){var t=e.payload,n=t.properties,o=t.options,r="Page View";o&&o.eventType&&(r=o.eventType),i.logEvent(r,n)},track:function(e){var t=e.payload,n=t.event,o=t.properties;i.logEvent(n,o)},identify:function(e){var t=e.payload,n=t.userId,o=t.traits;e.instance,i.setUserId(n),i.setUserProperties(o)},loaded:function(){return o},methods:{setSessionId:t}}}}();

@@ -36,2 +36,3 @@ 'use strict';

var apiKey = config.apiKey,
initialSessionId = config.initialSessionId,
customScriptSrc = config.customScriptSrc,

@@ -149,3 +150,9 @@ _config$integritySha = config.integritySha,

window.amplitude.init(config.apiKey, null, options, initComplete);
window.amplitude.init(config.apiKey, null, options, initComplete); // Set initial session id. Ref https://bit.ly/3vElAym
if (initialSessionId) {
setTimeout(function () {
return setSessionId(initialSessionId);
}, 10);
}
},

@@ -180,6 +187,29 @@ page: function page(_ref2) {

return amplitudeInitCompleted;
},
// https://getanalytics.io/plugins/writing-plugins/#adding-custom-methods
methods: {
/**
* analytics.plugins['amplitude'].setSessionId('your-id')
*/
setSessionId: setSessionId
}
};
}
/**
* Set Amplitude session ID. Ref https://bit.ly/3vElAym
* @param {string} sessionId - Minimum visit length before first page ping event fires
*/
function setSessionId(sessionId) {
if (typeof window.amplitude === 'undefined') {
console.log('Amplitude not loaded yet');
return false;
}
var amplitudeInstance = window.amplitude.getInstance();
amplitudeInstance.setSessionId(sessionId);
amplitudeInstance.enableTracking();
}
/* This module will shake out unused code + work in browser and node 🎉 */

@@ -186,0 +216,0 @@

@@ -34,2 +34,3 @@ function _typeof(obj) {

var apiKey = config.apiKey,
initialSessionId = config.initialSessionId,
customScriptSrc = config.customScriptSrc,

@@ -147,3 +148,9 @@ _config$integritySha = config.integritySha,

window.amplitude.init(config.apiKey, null, options, initComplete);
window.amplitude.init(config.apiKey, null, options, initComplete); // Set initial session id. Ref https://bit.ly/3vElAym
if (initialSessionId) {
setTimeout(function () {
return setSessionId(initialSessionId);
}, 10);
}
},

@@ -178,6 +185,29 @@ page: function page(_ref2) {

return amplitudeInitCompleted;
},
// https://getanalytics.io/plugins/writing-plugins/#adding-custom-methods
methods: {
/**
* analytics.plugins['amplitude'].setSessionId('your-id')
*/
setSessionId: setSessionId
}
};
}
/**
* Set Amplitude session ID. Ref https://bit.ly/3vElAym
* @param {string} sessionId - Minimum visit length before first page ping event fires
*/
function setSessionId(sessionId) {
if (typeof window.amplitude === 'undefined') {
console.log('Amplitude not loaded yet');
return false;
}
var amplitudeInstance = window.amplitude.getInstance();
amplitudeInstance.setSessionId(sessionId);
amplitudeInstance.enableTracking();
}
/* This module will shake out unused code + work in browser and node 🎉 */

@@ -184,0 +214,0 @@

{
"name": "@analytics/amplitude",
"version": "0.0.4",
"version": "0.1.0",
"description": "Amplitude integration for 'analytics' module",

@@ -54,3 +54,3 @@ "projectMeta": {

},
"gitHead": "5c11fbb66af2c83e6beb4239a751a651bd8d242e"
"gitHead": "a987851cb60fbd93a38bc6e35cffcace2167c06b"
}

@@ -249,1 +249,40 @@ <!--

<!-- AUTO-GENERATED-CONTENT:END (PLUGIN_DOCS) -->
## Setting Custom Session Ids
You can set a session id like so
```js
import Analytics from 'analytics'
import amplitudePlugin from '@analytics/amplitude'
const analytics = Analytics({
app: 'awesome-app',
plugins: [
amplitudePlugin({
apiKey: 'token',
})
]
})
// Run custom method https://getanalytics.io/plugins/writing-plugins/#adding-custom-methods
analytics.plugins['amplitude'].setSessionId('your-id')
```
Or via the `initialSessionId` config value
```js
import Analytics from 'analytics'
import amplitudePlugin from '@analytics/amplitude'
const analytics = Analytics({
app: 'awesome-app',
plugins: [
amplitudePlugin({
apiKey: 'token',
initialSessionId: 'xyz-123'
})
]
})
```
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