[analytics] add all available named events as built-in log methods

This commit is contained in:
Salakar
2019-09-14 22:27:32 +01:00
parent 7250cfbcb1
commit f9e91c7371
11 changed files with 13982 additions and 4394 deletions

View File

@@ -165,6 +165,7 @@ Support for handling an incoming app index URL has been added to React Native Fi
## Analytics (analytics)
- [NEW] Added support for `resetAnalyticsData()`
- [NEW] Added event specific methods for many built-in analytics events, e.g. `logLevelStart`, `logSearch`, `logSignUp` and many more, see the module reference documentation for the full list of methods added.
- [INTERNAL] `setUserProperties` now iterates properties natively (formerly 1 native call per property)
- [BREAKING] all analytics methods now return a Promise, rather than formerly being 'fire and forget'

14900
docs/typedoc.json vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -98,7 +98,9 @@
"**/react-native",
"**/react-native/**",
"**/stacktrace-js",
"**/stacktrace-js/**"
"**/stacktrace-js/**",
"**/superstruct",
"**/superstruct/**"
]
},
"dependencies": {

View File

@@ -96,7 +96,7 @@ describe('analytics()', () => {
firebase.analytics().logEvent('!@£$%^&*');
return Promise.reject(new Error('Did not throw.'));
} catch (e) {
e.message.should.containEql(`'name' invalid event name '!@£$%^&*'`);
e.message.should.containEql("'name' invalid event name '!@£$%^&*'");
return Promise.resolve();
}
});
@@ -339,4 +339,542 @@ describe('analytics()', () => {
await firebase.analytics().setUserProperties({ invertase3: 'rn-firebase' });
});
});
describe('logAddPaymentInfo()', () => {
it('calls logEvent', async () => {
await firebase.analytics().logAddPaymentInfo();
});
});
describe('logAddToCart()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logAddToCart();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logAddToCart({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
quantity: 1,
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logAddToCart', async () => {
await firebase.analytics().logAddToCart({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
quantity: 1,
item_location_id: 'foo',
start_date: '2019-01-01',
value: 123,
currency: 'GBP',
});
});
});
describe('logAddToWishlist()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logAddToWishlist();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logAddToWishlist({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
quantity: 1,
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logAddToWishlist', async () => {
await firebase.analytics().logAddToWishlist({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
quantity: 1,
item_location_id: 'foo',
value: 123,
currency: 'GBP',
});
});
});
describe('logAppOpen()', () => {
it('calls logAppOpen', async () => {
await firebase.analytics().logAppOpen();
});
});
describe('logBeginCheckout()', () => {
it('calls logBeginCheckout', async () => {
await firebase.analytics().logBeginCheckout();
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logBeginCheckout({
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
});
describe('logCampaignDetails()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logCampaignDetails();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logCampaignDetails', async () => {
await firebase.analytics().logCampaignDetails({
source: 'foo',
medium: 'bar',
campaign: 'baz',
});
});
});
describe('logEarnVirtualCurrency()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logEarnVirtualCurrency();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logEarnVirtualCurrency', async () => {
await firebase.analytics().logEarnVirtualCurrency({
virtual_currency_name: 'foo',
value: 123,
});
});
});
describe('logEcommercePurchase()', () => {
it('calls logEcommercePurchase with no params', async () => {
await firebase.analytics().logEcommercePurchase();
});
it('calls logEcommercePurchase', async () => {
await firebase.analytics().logEcommercePurchase({
currency: 'USD',
value: 123,
});
});
});
describe('logGenerateLead()', () => {
it('calls logGenerateLead with no params', async () => {
await firebase.analytics().logEcommercePurchase();
});
it('calls logGenerateLead', async () => {
await firebase.analytics().logEcommercePurchase({
currency: 'USD',
value: 123,
});
});
});
describe('logJoinGroup()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logJoinGroup();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logJoinGroup', async () => {
await firebase.analytics().logJoinGroup({
group_id: '123',
});
});
});
describe('logLevelEnd()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logLevelEnd();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logLevelEnd', async () => {
await firebase.analytics().logLevelEnd({
level: 123,
success: 'yes',
});
});
});
describe('logLevelStart()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logLevelStart();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logLevelEnd', async () => {
await firebase.analytics().logLevelStart({
level: 123,
});
});
});
describe('logLevelUp()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logLevelUp();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logLevelUp', async () => {
await firebase.analytics().logLevelUp({
level: 123,
character: 'foo',
});
});
});
describe('logLogin()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logLogin();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logLogin', async () => {
await firebase.analytics().logLogin({
method: 'facebook.com',
});
});
});
describe('logPostScore()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logPostScore();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logPostScore', async () => {
await firebase.analytics().logPostScore({
score: 123,
});
});
});
describe('logPresentOffer()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logPresentOffer();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logPresentOffer({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
quantity: 1,
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logPresentOffer', async () => {
await firebase.analytics().logPresentOffer({
item_id: '123',
item_name: '123',
item_category: '123',
quantity: 123,
});
});
});
describe('logPurchaseRefund()', () => {
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logPurchaseRefund({
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logPurchaseRefund with no params', async () => {
await firebase.analytics().logPurchaseRefund();
});
it('calls logPurchaseRefund', async () => {
await firebase.analytics().logPurchaseRefund({
transaction_id: '123',
});
});
});
describe('logRemoveFromCart()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logRemoveFromCart();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logRemoveFromCart({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logRemoveFromCart', async () => {
await firebase.analytics().logRemoveFromCart({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
});
});
});
describe('logSearch()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logSearch();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logSearch', async () => {
await firebase.analytics().logSearch({
search_term: 'foo',
});
});
});
describe('logSelectContent()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logSelectContent();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logSelectContent', async () => {
await firebase.analytics().logSelectContent({
content_type: 'foo',
item_id: 'foo',
});
});
});
describe('logSetCheckoutOption()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logSetCheckoutOption();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logSelectContent', async () => {
await firebase.analytics().logSetCheckoutOption({
checkout_step: 123,
checkout_option: 'foo',
});
});
});
describe('logShare()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logShare();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logShare', async () => {
await firebase.analytics().logShare({
content_type: 'foo',
item_id: 'foo',
});
});
});
describe('logSignUp()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logSignUp();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logSignUp', async () => {
await firebase.analytics().logSignUp({
method: 'facebook.com',
});
});
});
describe('logSpendVirtualCurrency()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logSpendVirtualCurrency();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logSpendVirtualCurrency', async () => {
await firebase.analytics().logSpendVirtualCurrency({
item_name: 'foo',
virtual_currency_name: 'foo',
value: 123,
});
});
});
describe('logTutorialBegin()', () => {
it('calls logTutorialBegin', async () => {
await firebase.analytics().logTutorialBegin();
});
});
describe('logTutorialComplete()', () => {
it('calls logTutorialComplete', async () => {
await firebase.analytics().logTutorialComplete();
});
});
describe('logUnlockAchievement()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logUnlockAchievement();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logUnlockAchievement', async () => {
await firebase.analytics().logUnlockAchievement({
achievement_id: 'foo',
});
});
});
describe('logViewItem()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logViewItem();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('errors when compound values are not set', async () => {
try {
await firebase.analytics().logViewItem({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
value: 123,
});
} catch (e) {
e.message.should.containEql('parameter, you must also supply the');
}
});
it('calls logUnlockAchievement', async () => {
await firebase.analytics().logViewItem({
item_id: 'foo',
item_name: 'foo',
item_category: 'foo',
});
});
});
describe('logViewItemList()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logViewItemList();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logViewItemList', async () => {
await firebase.analytics().logViewItemList({
item_category: 'foo',
});
});
});
describe('logViewSearchResults()', () => {
it('errors when no parameters are set', async () => {
try {
await firebase.analytics().logViewSearchResults();
} catch (e) {
e.message.should.containEql('The supplied arg must be an object of key/values');
}
});
it('calls logViewSearchResults', async () => {
await firebase.analytics().logViewSearchResults({
search_term: 'foo',
});
});
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -24,13 +24,17 @@ import {
isString,
isUndefined,
} from '@react-native-firebase/app/lib/common';
import { validateStruct, validateCompound } from '@react-native-firebase/app/lib/common/struct';
import {
createModuleNamespace,
FirebaseModule,
getFirebaseRoot,
} from '@react-native-firebase/app/lib/internal';
import { isBoolean } from '../../app/lib/common';
import version from './version';
import * as structs from './structs';
const ReservedEventNames = [
'app_clear_data',
@@ -201,6 +205,385 @@ class FirebaseAnalyticsModule extends FirebaseModule {
resetAnalyticsData() {
return this.native.resetAnalyticsData();
}
/** -------------------
* EVENTS
* -------------------- */
logAddPaymentInfo() {
return this.logEvent('add_payment_info');
}
logAddToCart(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logAddToCart(*): The supplied arg must be an object of key/values.',
);
}
validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToCart(*):');
return this.logEvent(
'add_payment_info',
validateStruct(object, structs.AddToCart, 'firebase.analytics().logAddToCart(*):'),
);
}
logAddToWishlist(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logAddToWishlist(*): The supplied arg must be an object of key/values.',
);
}
validateCompound(object, 'value', 'currency', 'firebase.analytics().logAddToWishlist(*):');
return this.logEvent(
'add_to_wishlist',
validateStruct(object, structs.AddToWishlist, 'firebase.analytics().logAddToWishlist(*):'),
);
}
logAppOpen() {
return this.logEvent('app_open');
}
logBeginCheckout(object = {}) {
validateCompound(object, 'value', 'currency', 'firebase.analytics().logBeginCheckout(*):');
return this.logEvent(
'begin_checkout',
validateStruct(object, structs.BeginCheckout, 'firebase.analytics().logBeginCheckout(*):'),
);
}
logCampaignDetails(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logCampaignDetails(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'campaign_details',
validateStruct(
object,
structs.CampaignDetails,
'firebase.analytics().logCampaignDetails(*):',
),
);
}
logEarnVirtualCurrency(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logEarnVirtualCurrency(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'earn_virtual_currency',
validateStruct(
object,
structs.EarnVirtualCurrency,
'firebase.analytics().logEarnVirtualCurrency(*):',
),
);
}
logEcommercePurchase(object = {}) {
validateCompound(object, 'value', 'currency', 'firebase.analytics().logEcommercePurchase(*):');
return this.logEvent(
'ecommerce_purchase',
validateStruct(
object,
structs.EcommercePurchase,
'firebase.analytics().logEcommercePurchase(*):',
),
);
}
logGenerateLead(object = {}) {
validateCompound(object, 'value', 'currency', 'firebase.analytics().logGenerateLead(*):');
return this.logEvent(
'generate_lead',
validateStruct(object, structs.GenerateLead, 'firebase.analytics().logGenerateLead(*):'),
);
}
logJoinGroup(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logJoinGroup(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'join_group',
validateStruct(object, structs.JoinGroup, 'firebase.analytics().logJoinGroup(*):'),
);
}
logLevelEnd(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logLevelEnd(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'level_end',
validateStruct(object, structs.LevelEnd, 'firebase.analytics().logLevelEnd(*):'),
);
}
logLevelStart(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logLevelStart(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'level_start',
validateStruct(object, structs.LevelStart, 'firebase.analytics().logLevelStart(*):'),
);
}
logLevelUp(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logLevelUp(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'level_up',
validateStruct(object, structs.LevelUp, 'firebase.analytics().logLevelUp(*):'),
);
}
logLogin(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logLogin(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'login',
validateStruct(object, structs.Login, 'firebase.analytics().logLogin(*):'),
);
}
logPostScore(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logPostScore(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'post_score',
validateStruct(object, structs.PostScore, 'firebase.analytics().logPostScore(*):'),
);
}
logPresentOffer(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logPresentOffer(*): The supplied arg must be an object of key/values.',
);
}
validateCompound(object, 'value', 'currency', 'firebase.analytics().logPresentOffer(*):');
return this.logEvent(
'present_offer',
validateStruct(object, structs.PresentOffer, 'firebase.analytics().logPresentOffer(*):'),
);
}
logPurchaseRefund(object = {}) {
validateCompound(object, 'value', 'currency', 'firebase.analytics().logPresentOffer(*):');
return this.logEvent(
'purchase_refund',
validateStruct(object, structs.PurchaseRefund, 'firebase.analytics().logPurchaseRefund(*):'),
);
}
logRemoveFromCart(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logRemoveFromCart(*): The supplied arg must be an object of key/values.',
);
}
validateCompound(object, 'value', 'currency', 'firebase.analytics().logRemoveFromCart(*):');
return this.logEvent(
'remove_from_cart',
validateStruct(object, structs.RemoveFromCart, 'firebase.analytics().logRemoveFromCart(*):'),
);
}
logSearch(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logSearch(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'search',
validateStruct(object, structs.Search, 'firebase.analytics().logSearch(*):'),
);
}
logSelectContent(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logSelectContent(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'select_content',
validateStruct(object, structs.SelectContent, 'firebase.analytics().logSelectContent(*):'),
);
}
logSetCheckoutOption(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logSetCheckoutOption(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'set_checkout_option',
validateStruct(
object,
structs.SetCheckoutOption,
'firebase.analytics().logSetCheckoutOption(*):',
),
);
}
logShare(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logShare(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'share',
validateStruct(object, structs.Share, 'firebase.analytics().logShare(*):'),
);
}
logSignUp(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logSignUp(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'sign_up',
validateStruct(object, structs.SignUp, 'firebase.analytics().logSignUp(*):'),
);
}
logSpendVirtualCurrency(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logSpendVirtualCurrency(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'spend_virtual_currency',
validateStruct(
object,
structs.SpendVirtualCurrency,
'firebase.analytics().logSpendVirtualCurrency(*):',
),
);
}
logTutorialBegin() {
return this.logEvent('tutorial_begin');
}
logTutorialComplete() {
return this.logEvent('tutorial_complete');
}
logUnlockAchievement(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logUnlockAchievement(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'unlock_achievement',
validateStruct(
object,
structs.UnlockAchievement,
'firebase.analytics().logUnlockAchievement(*):',
),
);
}
logViewItem(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logViewItem(*): The supplied arg must be an object of key/values.',
);
}
validateCompound(object, 'value', 'currency', 'firebase.analytics().logViewItem(*):');
return this.logEvent(
'view_item',
validateStruct(object, structs.ViewItem, 'firebase.analytics().logViewItem(*):'),
);
}
logViewItemList(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logViewItemList(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'view_item_list',
validateStruct(object, structs.ViewItemList, 'firebase.analytics().logViewItemList(*):'),
);
}
logViewSearchResults(object) {
if (!isObject(object)) {
throw new Error(
'firebase.analytics().logViewSearchResults(*): The supplied arg must be an object of key/values.',
);
}
return this.logEvent(
'view_search_results',
validateStruct(
object,
structs.ViewSearchResults,
'firebase.analytics().logViewSearchResults(*):',
),
);
}
}
// import { SDK_VERSION } from '@react-native-firebase/analytics';

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,224 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import struct from '@react-native-firebase/app/lib/common/struct';
export const AddToCart = struct({
item_id: 'string',
item_name: 'string',
item_category: 'string',
quantity: 'number',
price: 'number?',
value: 'number?',
currency: 'string?',
origin: 'string?',
item_location_id: 'string?',
destination: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
});
export const AddToWishlist = struct({
item_id: 'string',
item_name: 'string',
item_category: 'string',
quantity: 'number',
price: 'number?',
value: 'number?',
currency: 'string?',
item_location_id: 'string?',
});
export const BeginCheckout = struct({
value: 'number?',
currency: 'string?',
transaction_id: 'string?',
number_of_nights: 'number?',
number_of_rooms: 'number?',
number_of_passengers: 'number?',
origin: 'string?',
destination: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
travel_class: 'shortDate?',
});
export const CampaignDetails = struct({
source: 'string',
medium: 'string',
campaign: 'string',
term: 'string?',
content: 'string?',
aclid: 'string?',
cp1: 'string?',
});
export const EarnVirtualCurrency = struct({
virtual_currency_name: 'string',
value: 'number',
});
export const EcommercePurchase = struct({
currency: 'string?',
value: 'number?',
transaction_id: 'string?',
tax: 'number?',
shipping: 'number?',
coupon: 'string?',
location: 'string?',
number_of_nights: 'number?',
number_of_rooms: 'number?',
number_of_passengers: 'number?',
origin: 'string?',
destination: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
travel_class: 'string?',
});
export const GenerateLead = struct({
currency: 'string?',
value: 'number?',
});
export const JoinGroup = struct({
group_id: 'string',
});
export const LevelEnd = struct({
level: 'number',
success: 'string?',
});
export const LevelStart = struct({
level: 'number',
});
export const LevelUp = struct({
level: 'number',
character: 'string?',
});
export const Login = struct({
method: 'string',
});
export const PostScore = struct({
score: 'number',
level: 'number?',
character: 'string?',
});
export const PresentOffer = struct({
item_id: 'string',
item_name: 'string',
item_category: 'string',
quantity: 'number',
price: 'number?',
value: 'number?',
currency: 'string?',
item_location_id: 'string?',
});
export const PurchaseRefund = struct({
currency: 'string?',
value: 'number?',
transaction_id: 'string?',
});
export const RemoveFromCart = struct({
item_id: 'string',
item_name: 'string',
item_category: 'string',
quantity: 'number?',
value: 'number?',
price: 'number?',
currency: 'string?',
item_location_id: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
origin: 'string?',
destination: 'string?',
});
export const Search = struct({
search_term: 'string',
number_of_nights: 'number?',
number_of_rooms: 'number?',
number_of_passengers: 'number?',
origin: 'string?',
destination: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
travel_class: 'string?',
});
export const SelectContent = struct({
content_type: 'string',
item_id: 'string',
});
export const SetCheckoutOption = struct({
checkout_step: 'number',
checkout_option: 'string',
});
export const Share = struct({
content_type: 'string',
item_id: 'string',
});
export const SignUp = struct({
method: 'string',
});
export const SpendVirtualCurrency = struct({
item_name: 'string',
virtual_currency_name: 'string',
value: 'number',
});
export const UnlockAchievement = struct({
achievement_id: 'string',
});
export const ViewItem = struct({
item_id: 'string',
item_name: 'string',
item_category: 'string',
item_location_id: 'string?',
price: 'number?',
quantity: 'number?',
currency: 'string?',
value: 'number?',
flight_number: 'string?',
number_of_passengers: 'number?',
number_of_nights: 'number?',
number_of_rooms: 'number?',
origin: 'string?',
destination: 'string?',
start_date: 'shortDate?',
end_date: 'shortDate?',
search_term: 'string?',
travel_class: 'string?',
});
export const ViewItemList = struct({
item_category: 'string',
});
export const ViewSearchResults = struct({
search_term: 'string',
});

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { superstruct } from 'superstruct/lib/index';
import { isUndefined } from './validate';
export default superstruct({
types: {
shortDate: value => typeof value === 'string' && !!value.match(/^\d{4}-\d{2}-\d{2}$/),
},
});
export const validateStruct = (value = {}, struct, prefix = '') => {
try {
return struct(value);
} catch (e) {
const { path, reason } = e;
const key = path[0];
if (reason === undefined) {
throw new Error(`${prefix} unknown property '${key}'.`);
}
e.message = `${prefix} ${e.message}`;
throw e;
}
};
export const validateCompound = (source = {}, a, b, prefix = '') => {
if (isUndefined(source[a]) && !isUndefined(source[b])) {
throw new Error(
`${prefix} if you supply the '${a}' parameter, you must also supply the '${b}' parameter.`,
);
}
};

View File

@@ -54,6 +54,7 @@
},
"dependencies": {
"@react-native-firebase/app-types": "0.4.0",
"superstruct": "^0.6.2",
"opencollective-postinstall": "^2.0.1"
},
"collective": {