Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
feat(types): add typings for ecommerce
Browse files Browse the repository at this point in the history
  • Loading branch information
romansp committed Dec 15, 2019
1 parent d2a797c commit 440d2e2
Showing 1 changed file with 133 additions and 1 deletion.
134 changes: 133 additions & 1 deletion vue-analytics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,138 @@ declare module 'vue-analytics' {
}): void;
}

interface EcommerceItem {
id: string;
name: string;
sku?: string;
category?: string;
price?: string;
quantity?: number;
}

interface EcommerceTransaction {
id: string;
affiliation?: string;
revenue?: string;
shipping?: string;
tax?: string;
}

interface EcommerceImpressionBase {
list?: string;
brand?: string;
category?: string;
variant?: string;
position?: number;
price?: string;
}

interface EcommerceImpressionWithId extends EcommerceImpressionBase {
id: string;
}

interface EcommerceImpressionWithName extends EcommerceImpressionBase {
name: string;
}

type EcommerceImpression = EcommerceImpressionWithId | EcommerceImpressionWithName;

interface EcommerceProductBase {
brand?: string;
category?: string;
variant?: string;
price?: string;
quantity?: number;
coupon?: string;
position?: number;
}

interface EcommerceProductWithId extends EcommerceProductBase {
id: string;
}

interface EcommerceProductWithName extends EcommerceProductBase {
name: string;
}

type EcommerceProduct = EcommerceImpressionWithId | EcommerceImpressionWithName;

type EcommerceAction =
| 'click'
| 'detail'
| 'add'
| 'remove'
| 'checkout'
| 'checkout_option'
| 'purchase'
| 'refund'
| 'promo_click'

interface EcommerceActionData {
id?: string;
affiliation?: string;
revenue?: number;
tax?: number;
shipping?: number;
coupon?: string;
list?: string;
step?: number;
option?: string;
}

interface EcommercePromoBase {
creative?: string;
position?: string;
}

interface EcommercePromoWithId extends EcommercePromoBase {
id: string;
}

interface EcommercePromoWithName extends EcommercePromoBase {
name: string;
}

type EcommercePromo = EcommercePromoWithId | EcommercePromoWithName;

interface Ecommerce {
addItem(item: EcommerceItem): void;
addTransaction(transaction: EcommerceTransaction): void;
addProduct(product: EcommerceProduct): void;
addImpression(impression: EcommerceImpression): void;
setAction(action: EcommerceAction, data: EcommerceActionData): void;
addPromo(product: EcommercePromo): void;
send(): void;
}

interface screenviewFn {
(screen: string) :void;
(option: {
screenName: string;
[otherProperties: string]: any;
}): void;
}

interface requireFn {
(pluginName: string, options?: any): void
}

interface exceptionFn {
(exception: Error | string): void;
}

interface queryFn {
(...args: any[]): any;
}

interface analyticsMiddlewareFn {
<T>(store: Store<T>): void;
}

interface onAnalyticsReadyFn {
(): Promise<void>;
}

export interface InstallOptions {
id: string | string[] | (() => string) | (() => Promise<string>) | Promise<string>,
router?: VueRouter,
Expand Down Expand Up @@ -107,7 +239,7 @@ declare module 'vue-analytics' {
analyticsMiddleware: any;
onAnalyticsReady: () => Promise<void>;
event: eventFn;
ecommerce: any;
ecommerce: Ecommerce;
set: setFn;
page: pageFn;
query: any;
Expand Down

0 comments on commit 440d2e2

Please sign in to comment.