@itly/plugin-amplitude
Advanced tools
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| # [2.5.0](https://github.com/amplitude/itly-sdk/compare/v2.4.0...v2.5.0) (2021-10-12) | ||
| ### Features | ||
| * amp-43407 add support for amplitude plugin support ([#134](https://github.com/amplitude/itly-sdk/issues/134)) ([686806a](https://github.com/amplitude/itly-sdk/commit/686806a38fb7a02cb9eb9469d1509b6b5927b416)) | ||
| # [2.4.0](https://github.com/amplitude/itly-sdk/compare/v2.3.4...v2.4.0) (2021-10-01) | ||
@@ -8,0 +19,0 @@ |
@@ -12,2 +12,6 @@ import { Event, Properties, RequestLoggerPlugin, PluginLoadOptions, PluginCallOptions } from '@itly/sdk'; | ||
| export interface AmplitudeGroupOptions extends AmplitudeCallOptions { | ||
| groups?: { | ||
| [name: string]: string | string[]; | ||
| }; | ||
| callback?: AmplitudeCallback; | ||
| } | ||
@@ -30,2 +34,3 @@ export interface AmplitudePageOptions extends AmplitudeCallOptions { | ||
| identify(userId: string | undefined, properties?: Properties, options?: AmplitudeIdentifyOptions): void; | ||
| group(userId: string | undefined, groupId: string, properties?: Properties, options?: AmplitudeGroupOptions): void; | ||
| track(userId: string | undefined, { name, properties }: Event, options?: AmplitudeTrackOptions): void; | ||
@@ -32,0 +37,0 @@ reset(): void; |
+42
-0
@@ -81,2 +81,44 @@ "use strict"; | ||
| }; | ||
| AmplitudePlugin.prototype.group = function (userId, groupId, properties, options) { | ||
| var _this = this; | ||
| if (!(options && options.groups)) { | ||
| this.logger.warn('Amplitude group requires groups in the AmplitudeGroupOptions.'); | ||
| return; | ||
| } | ||
| var identifyObject; | ||
| var wrappedCallback; | ||
| if (properties) { | ||
| identifyObject = new this.amplitude.Identify(); | ||
| for (var p in properties) { | ||
| if (!properties.hasOwnProperty(p)) { | ||
| continue; | ||
| } | ||
| identifyObject.set(p, properties[p]); | ||
| } | ||
| var callback = (options !== null && options !== void 0 ? options : {}).callback; | ||
| var responseLogger = this.logger.logRequest('groupIdentify', userId + " " + JSON.stringify(properties)); | ||
| wrappedCallback = this.wrapCallback(responseLogger, callback); | ||
| } | ||
| var _loop_1 = function (groupType) { | ||
| if (!options.groups.hasOwnProperty(groupType)) { | ||
| return "continue"; | ||
| } | ||
| var groupName = options.groups[groupType]; | ||
| this_1.amplitude.getInstance().setGroup(groupType, groupName); | ||
| if (identifyObject) { | ||
| if (Array.isArray(groupName)) { | ||
| groupName.forEach(function (groupValue) { | ||
| _this.amplitude.getInstance().groupIdentify(groupType, groupValue, identifyObject, wrappedCallback); | ||
| }); | ||
| } | ||
| else { | ||
| this_1.amplitude.getInstance().groupIdentify(groupType, groupName, identifyObject, wrappedCallback); | ||
| } | ||
| } | ||
| }; | ||
| var this_1 = this; | ||
| for (var groupType in options.groups) { | ||
| _loop_1(groupType); | ||
| } | ||
| }; | ||
| AmplitudePlugin.prototype.track = function (userId, _a, options) { | ||
@@ -83,0 +125,0 @@ var name = _a.name, properties = _a.properties; |
@@ -12,2 +12,6 @@ import { Event, Properties, RequestLoggerPlugin, PluginLoadOptions, PluginCallOptions } from '@itly/sdk'; | ||
| export interface AmplitudeGroupOptions extends AmplitudeCallOptions { | ||
| groups?: { | ||
| [name: string]: string | string[]; | ||
| }; | ||
| callback?: AmplitudeCallback; | ||
| } | ||
@@ -30,2 +34,3 @@ export interface AmplitudePageOptions extends AmplitudeCallOptions { | ||
| identify(userId: string | undefined, properties?: Properties, options?: AmplitudeIdentifyOptions): void; | ||
| group(userId: string | undefined, groupId: string, properties?: Properties, options?: AmplitudeGroupOptions): void; | ||
| track(userId: string | undefined, { name, properties }: Event, options?: AmplitudeTrackOptions): void; | ||
@@ -32,0 +37,0 @@ reset(): void; |
+42
-0
@@ -78,2 +78,44 @@ var __extends = (this && this.__extends) || (function () { | ||
| }; | ||
| AmplitudePlugin.prototype.group = function (userId, groupId, properties, options) { | ||
| var _this = this; | ||
| if (!(options && options.groups)) { | ||
| this.logger.warn('Amplitude group requires groups in the AmplitudeGroupOptions.'); | ||
| return; | ||
| } | ||
| var identifyObject; | ||
| var wrappedCallback; | ||
| if (properties) { | ||
| identifyObject = new this.amplitude.Identify(); | ||
| for (var p in properties) { | ||
| if (!properties.hasOwnProperty(p)) { | ||
| continue; | ||
| } | ||
| identifyObject.set(p, properties[p]); | ||
| } | ||
| var callback = (options !== null && options !== void 0 ? options : {}).callback; | ||
| var responseLogger = this.logger.logRequest('groupIdentify', userId + " " + JSON.stringify(properties)); | ||
| wrappedCallback = this.wrapCallback(responseLogger, callback); | ||
| } | ||
| var _loop_1 = function (groupType) { | ||
| if (!options.groups.hasOwnProperty(groupType)) { | ||
| return "continue"; | ||
| } | ||
| var groupName = options.groups[groupType]; | ||
| this_1.amplitude.getInstance().setGroup(groupType, groupName); | ||
| if (identifyObject) { | ||
| if (Array.isArray(groupName)) { | ||
| groupName.forEach(function (groupValue) { | ||
| _this.amplitude.getInstance().groupIdentify(groupType, groupValue, identifyObject, wrappedCallback); | ||
| }); | ||
| } | ||
| else { | ||
| this_1.amplitude.getInstance().groupIdentify(groupType, groupName, identifyObject, wrappedCallback); | ||
| } | ||
| } | ||
| }; | ||
| var this_1 = this; | ||
| for (var groupType in options.groups) { | ||
| _loop_1(groupType); | ||
| } | ||
| }; | ||
| AmplitudePlugin.prototype.track = function (userId, _a, options) { | ||
@@ -80,0 +122,0 @@ var name = _a.name, properties = _a.properties; |
+2
-2
| { | ||
| "name": "@itly/plugin-amplitude", | ||
| "version": "2.4.0", | ||
| "version": "2.5.0", | ||
| "description": "Amplitude Browser Plugin for Iteratively SDK", | ||
@@ -46,3 +46,3 @@ "main": "dist/cjs/index.js", | ||
| }, | ||
| "gitHead": "791f405d0d750b88794d67177ca23dff5a118403" | ||
| "gitHead": "d184ff836f749c84415a74a9c968978b9f2ec4ec" | ||
| } |
33069
15.47%373
33.69%