Skip to content

Update analytics ecommerce event and param types #2728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions packages/analytics-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export interface EventParams {
value?: number;
event_label?: string;
event_category?: string;
shipping_tier?: string;
item_list?: string;
item_list_id?: string;
item_list_name?: string;
promotion_id?: string;
promotion_name?: string;
payment_type?: string;
affiliation?: string;
}

/**
Expand All @@ -158,6 +166,7 @@ export interface CustomParams {
*/
export type EventNameString =
| 'add_payment_info'
| 'add_shipping_info'
| 'add_to_cart'
| 'add_to_wishlist'
| 'begin_checkout'
Expand All @@ -172,10 +181,13 @@ export type EventNameString =
| 'screen_view'
| 'search'
| 'select_content'
| 'select_item'
| 'select_promotion'
| 'set_checkout_option'
| 'share'
| 'sign_up'
| 'timing_complete'
| 'view_cart'
| 'view_item'
| 'view_item_list'
| 'view_promotion'
Expand All @@ -184,17 +196,39 @@ export type EventNameString =
export type Currency = string | number;

export interface Item {
brand?: string;
category?: string;
item_id?: string;
item_name?: string;
item_brand?: string;
item_category?: string;
item_category2?: string;
item_category3?: string;
item_category4?: string;
item_category5?: string;
item_variant?: string;
price?: Currency;
quantity?: number;
index?: string;
coupon?: string;
item_list_name?: string;
item_list_id?: string;
discount?: Currency;
affiliation?: string;
creative_name?: string;
creative_slot?: string;
id?: string;
promotion_id?: string;
promotion_name?: string;
location_id?: string;
/** @deprecated Use item_brand instead. */
brand?: string;
/** @deprecated Use item_category instead. */
category?: string;
/** @deprecated Use item_id instead. */
id?: string;
/** @deprecated Use item_name instead. */
name?: string;
price?: Currency;
quantity?: number;
}

/** @deprecated Use Item instead. */
export interface Promotion {
creative_name?: string;
creative_slot?: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/analytics/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export enum GtagCommand {
* Any other string is also allowed.
*/
export enum EventName {
ADD_SHIPPING_INFO = 'add_shipping_info',
ADD_PAYMENT_INFO = 'add_payment_info',
ADD_TO_CART = 'add_to_cart',
ADD_TO_WISHLIST = 'add_to_wishlist',
BEGIN_CHECKOUT = 'begin_checkout',
/** @deprecated */
CHECKOUT_PROGRESS = 'checkout_progress',
EXCEPTION = 'exception',
GENERATE_LEAD = 'generate_lead',
Expand All @@ -49,10 +51,14 @@ export enum EventName {
SCREEN_VIEW = 'screen_view',
SEARCH = 'search',
SELECT_CONTENT = 'select_content',
SELECT_ITEM = 'select_item',
SELECT_PROMOTION = 'select_promotion',
/** @deprecated */
SET_CHECKOUT_OPTION = 'set_checkout_option',
SHARE = 'share',
SIGN_UP = 'sign_up',
TIMING_COMPLETE = 'timing_complete',
VIEW_CART = 'view_cart',
VIEW_ITEM = 'view_item',
VIEW_ITEM_LIST = 'view_item_list',
VIEW_PROMOTION = 'view_promotion',
Expand Down
147 changes: 118 additions & 29 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4008,7 +4008,35 @@ declare namespace firebase.analytics {
*/
logEvent(
eventName: 'add_payment_info',
eventParams?: { [key: string]: any },
eventParams?: {
coupon?: EventParams['coupon'];
currency?: EventParams['currency'];
items?: EventParams['items'];
payment_type?: EventParams['payment_type'];
value?: EventParams['value'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
): void;

/**
* Sends analytics event with given `eventParams`. This method
* automatically associates this logged event with this Firebase web
* app instance on this device.
* List of official event parameters can be found in
* {@link https://developers.google.com/gtagjs/reference/event
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'add_shipping_info',
eventParams: {
coupon?: EventParams['coupon'];
currency?: EventParams['currency'];
items?: EventParams['items'];
shipping_tier?: EventParams['shipping_tier'];
value?: EventParams['value'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
): void;

Expand Down Expand Up @@ -4155,7 +4183,7 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'purchase',
eventName: 'purchase' | 'refund',
eventParams: {
value?: EventParams['value'];
currency?: EventParams['currency'];
Expand All @@ -4164,6 +4192,7 @@ declare namespace firebase.analytics {
shipping?: EventParams['shipping'];
items?: EventParams['items'];
coupon?: EventParams['coupon'];
affiliation?: EventParams['affiliation'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand All @@ -4178,14 +4207,13 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'refund',
eventName: 'screen_view',
eventParams: {
value?: EventParams['value'];
currency?: EventParams['currency'];
transaction_id: EventParams['transaction_id'];
tax?: EventParams['tax'];
shipping?: EventParams['shipping'];
items?: EventParams['items'];
app_name: string;
screen_name: EventParams['screen_name'];
app_id?: string;
app_version?: string;
app_installer_id?: string;
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand All @@ -4200,13 +4228,9 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'screen_view',
eventName: 'search' | 'view_search_results',
eventParams: {
app_name: string;
screen_name: EventParams['screen_name'];
app_id?: string;
app_version?: string;
app_installer_id?: string;
search_term?: EventParams['search_term'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand All @@ -4221,9 +4245,12 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'search' | 'view_search_results',
eventName: 'select_content',
eventParams: {
search_term?: EventParams['search_term'];
items?: EventParams['items'];
promotions?: EventParams['promotions'];
content_type?: EventParams['content_type'];
content_id?: EventParams['content_id'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand All @@ -4238,12 +4265,30 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'select_content',
eventName: 'select_item',
eventParams: {
items?: EventParams['items'];
promotions?: EventParams['promotions'];
content_type?: EventParams['content_type'];
content_id?: EventParams['content_id'];
item_list_name?: EventParams['item_list_name'];
item_list_id?: EventParams['item_list_id'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
): void;

/**
* Sends analytics event with given `eventParams`. This method
* automatically associates this logged event with this Firebase web
* app instance on this device.
* List of official event parameters can be found in
* {@link https://developers.google.com/gtagjs/reference/event
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'select_promotion' | 'view_promotion',
eventParams: {
items?: EventParams['items'];
promotion_id?: EventParams['promotion_id'];
promotion_name?: EventParams['promotion_name'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand Down Expand Up @@ -4332,9 +4377,11 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'view_item' | 'view_item_list',
eventName: 'view_cart' | 'view_item',
eventParams: {
currency?: EventParams['currency'];
items?: EventParams['items'];
value?: EventParams['value'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand All @@ -4349,9 +4396,11 @@ declare namespace firebase.analytics {
* the gtag.js reference documentation}.
*/
logEvent(
eventName: 'view_promotion',
eventName: 'view_item_list',
eventParams: {
promotions?: EventParams['promotions'];
items?: EventParams['items'];
item_list_name?: EventParams['item_list_name'];
item_list_id?: EventParams['item_list_id'];
[key: string]: any;
},
options?: firebase.analytics.AnalyticsCallOptions
Expand Down Expand Up @@ -4477,6 +4526,14 @@ declare namespace firebase.analytics {
value?: number;
event_label?: string;
event_category: string;
shipping_tier?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal only adds the following:

  // New suggested event parameters.
  shipping_tier?: string;
  item_list?: string;
  item_list_id?: string;
  payment_type?: string;

Where are the other ones defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item_list is not present in the sheet. I think it has been replaced by item_list_name, see comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

item_list?: string;
item_list_id?: string;
item_list_name?: string;
promotion_id?: string;
promotion_name?: string;
payment_type?: string;
affiliation?: string;
}

/**
Expand All @@ -4492,6 +4549,7 @@ declare namespace firebase.analytics {
*/
export type EventNameString =
| 'add_payment_info'
| 'add_shipping_info'
| 'add_to_cart'
| 'add_to_wishlist'
| 'begin_checkout'
Expand All @@ -4506,10 +4564,13 @@ declare namespace firebase.analytics {
| 'screen_view'
| 'search'
| 'select_content'
| 'select_item'
| 'select_promotion'
| 'set_checkout_option'
| 'share'
| 'sign_up'
| 'timing_complete'
| 'view_cart'
| 'view_item'
| 'view_item_list'
| 'view_promotion'
Expand All @@ -4522,9 +4583,11 @@ declare namespace firebase.analytics {
*/
export enum EventName {
ADD_PAYMENT_INFO = 'add_payment_info',
ADD_SHIPPING_INFO = 'add_shipping_info',
ADD_TO_CART = 'add_to_cart',
ADD_TO_WISHLIST = 'add_to_wishlist',
BEGIN_CHECKOUT = 'begin_checkout',
/** @deprecated */
CHECKOUT_PROGRESS = 'checkout_progress',
EXCEPTION = 'exception',
GENERATE_LEAD = 'generate_lead',
Expand All @@ -4536,10 +4599,14 @@ declare namespace firebase.analytics {
SCREEN_VIEW = 'screen_view',
SEARCH = 'search',
SELECT_CONTENT = 'select_content',
SELECT_ITEM = 'select_item',
SELECT_PROMOTION = 'select_promotion',
/** @deprecated */
SET_CHECKOUT_OPTION = 'set_checkout_option',
SHARE = 'share',
SIGN_UP = 'sign_up',
TIMING_COMPLETE = 'timing_complete',
VIEW_CART = 'view_cart',
VIEW_ITEM = 'view_item',
VIEW_ITEM_LIST = 'view_item_list',
VIEW_PROMOTION = 'view_promotion',
Expand All @@ -4549,17 +4616,39 @@ declare namespace firebase.analytics {
export type Currency = string | number;

export interface Item {
brand?: string;
category?: string;
item_id?: string;
item_name?: string;
item_brand?: string;
item_category?: string;
item_category2?: string;
item_category3?: string;
item_category4?: string;
item_category5?: string;
item_variant?: string;
price?: Currency;
quantity?: number;
index?: string;
coupon?: string;
item_list_name?: string;
item_list_id?: string;
discount?: Currency;
affiliation?: string;
creative_name?: string;
creative_slot?: string;
id?: string;
promotion_id?: string;
promotion_name?: string;
location_id?: string;
/** @deprecated Use item_brand instead. */
brand?: string;
/** @deprecated Use item_category instead. */
category?: string;
/** @deprecated Use item_id instead. */
id?: string;
/** @deprecated Use item_name instead. */
name?: string;
price?: Currency;
quantity?: number;
}

/** @deprecated Use Item instead. */
export interface Promotion {
creative_name?: string;
creative_slot?: string;
Expand Down