Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function amplitudeClientTests() {
const client: AmplitudeClient = amplitude.getInstance();
//* Identify
(client.Identify: typeof Identify);
//* Revenue
(client.Revenue: typeof Revenue);
//* init
client.init('key');
client.init('key', 'uid');
client.init('key', null, { batchEvents: false });
client.init('key', 'uid', null, function(c: AmplitudeClient) {});
//* isNewSession
(client.isNewSession(): boolean);
function getInstanceTest() {
(amplitude.getInstance(): AmplitudeClient);
(amplitude.getInstance('name'): AmplitudeClient);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(5);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(new Date());
}
// @flow
/* eslint-disable no-unused-vars, no-undef, no-console */
import amplitude, { Identify, Revenue } from 'amplitude-js';
import type { AmplitudeClient } from 'amplitude-js';
/**
* Common instances
*/
const client = amplitude.getInstance();
const identify = new Identify();
const revenue = new Revenue();
const callback = (responseCode: number, responseBody: string) => void 0;
/**
* ALL THE TESTS START FROM HERE
*/
function getInstanceTest() {
(amplitude.getInstance(): AmplitudeClient);
(amplitude.getInstance('name'): AmplitudeClient);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(5);
// $ExpectError: getInstance only accepts strings
function getInstanceTest() {
(amplitude.getInstance(): AmplitudeClient);
(amplitude.getInstance('name'): AmplitudeClient);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(5);
// $ExpectError: getInstance only accepts strings
amplitude.getInstance(new Date());
}
import amplitude from 'amplitude-js';
import Analytics from 'appcenter-analytics';
amplitude.getInstance().init('8b7cf19e8eea3cdcf16340f5fbf16330', null, {
useNativeDeviceInfo: true,
});
let A = async event => {
amplitude.getInstance().logEvent(event, {});
try {
Analytics.trackEvent(event);
} catch (err) {
console.log(err);
}
};
A.ENUM = {
INIT: 'INIT',
GOT_NONZERO_BALANCE: 'GOT_NONZERO_BALANCE',
CREATED_WALLET: 'CREATED_WALLET',
return new Promise(resolve => {
const key =
process.env.NODE_ENV === 'production'
? '16621e1ae779c55cd67c2eda1610325b'
: 'd78524420bd27e783198933c03a59aca'
amplitude.getInstance().init(key, null, null, resolve)
})
}
initialize() {
amplitude.getInstance().init(this.apiKey);
}
sendEvent(event) {
let properties = {
category: event.categoryName
};
if (event.properties) {
properties = Object.assign({}, event.properties, properties);
}
amplitude.getInstance().logEvent(event.eventName, properties);
}
}
export function trackEvent(eventName, eventProperties) {
if (process.env.NODE_ENV === "production") {
try {
const amplitude = require("amplitude-js")
amplitude.getInstance().logEvent(eventName, eventProperties)
} catch (e) {
debug(eventName, eventProperties)
debug("Failed to send event to Amplitude", e)
}
} else {
debug(eventName, eventProperties)
}
}
export const setupUser = userInfo => {
const { username: userId } = userInfo;
amplitude.getInstance().setUserId(userId);
let userIdentity = new amplitude.Identify();
Object.keys(userInfo).forEach(function(key) {
userIdentity.set(key, userInfo[key]);
});
amplitude.getInstance().identify(userIdentity);
};