Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/app-events-checkout-customer-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

`appEvents`: add `shopify.appEvents.emit(eventHandle, attributes?)` to the Checkout standard and address-autocomplete APIs and the Customer Account standard API, for reporting app events to Shopify
1 change: 1 addition & 0 deletions packages/ui-extensions-tester/src/checkout/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function createSharedApiMocks() {
visitor: async () => ({type: 'success' as const}),
},
i18n: createMockI18n(),
appEvents: {emit: async () => ({success: true as const})},
sessionToken: {get: async () => 'mock-session-token'},
shop: {
id: 'gid://shopify/Shop/1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function createStandardApiProperties<T extends ExtensionTarget>(target: T) {
},
i18n: createMockI18n(),
storage: createStorage(),
appEvents: {emit: async () => ({success: true as const})},
sessionToken: {get: async () => 'mock-session-token'},
analytics: {
publish: async () => true,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-extensions/src/surfaces/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export type {
Shop,
Version,
Metafield,
AppEventAttributeValue,
AppEventAttributes,
AppEventEmitResult,
AppEvents,
AppMetafield,
AppMetafieldEntryTarget,
AppMetafieldEntry,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
Analytics,
AppEvents,
AppMetafieldEntry,
Capability,
CheckoutToken,
Expand Down Expand Up @@ -48,6 +49,11 @@ export interface AddressAutocompleteStandardApi<
*/
analytics: Analytics;

/**
* Reports events to Shopify for this app.
*/
appEvents: AppEvents;

/**
* The custom attributes left by the customer to the merchant, either in their cart or during checkout.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ export interface StandardApi<Target extends ExtensionTarget = ExtensionTarget> {
*/
analytics: Analytics;

/**
* Reports events to Shopify for this app.
*/
appEvents: AppEvents;

/**
* The gift cards that have been applied to the checkout. Each entry includes
* the last four characters of the gift card code, the amount used at
Expand Down Expand Up @@ -1690,6 +1695,51 @@ export interface Analytics {
*/
visitor(data: {email?: string; phone?: string}): Promise<VisitorResult>;
}

/**
* A value attached to an app event.
* @publicDocs
*/
export type AppEventAttributeValue = string | number | boolean;

/**
* Attributes related to an app event.
* @publicDocs
*/
export type AppEventAttributes = Record<string, AppEventAttributeValue>;

/**
* The outcome of an `emit` call.
*
* `success: true` means the host accepted the event. It does not confirm delivery.
*
* `success: false` means the event was not sent. `error` describes why.
* @publicDocs
*/
export type AppEventEmitResult =
| {readonly success: true}
| {readonly success: false; readonly error: string};

/**
* Reports events to Shopify for this app.
* @publicDocs
*/
export interface AppEvents {
/**
* Reports one occurrence of an app-defined event.
*
* @param eventHandle The app-defined event name.
* @param attributes Attributes related to this event.
* @default {}
* @returns A promise that resolves with the outcome once the host has
* handled the call.
*/
emit(
eventHandle: string,
attributes?: AppEventAttributes,
): Promise<AppEventEmitResult>;
}

/**
* Represents a visitor result.
* @publicDocs
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-extensions/src/surfaces/customer-account/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export type {
VisitorSuccess,
VisitorError,
SubscribableSignalLike,
AppEventAttributeValue,
AppEventAttributes,
AppEventEmitResult,
AppEvents,
} from './api/shared';

export type {CartLineItemApi} from './api/cart-line/cart-line-item';
Expand Down
10 changes: 10 additions & 0 deletions packages/ui-extensions/src/surfaces/customer-account/api/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import type {
} from '../../../shared';

import type {SubscribableSignalLike} from '../../checkout/shared';
import type {
AppEventAttributeValue,
AppEventAttributes,
AppEventEmitResult,
AppEvents,
} from '../../checkout/api/standard/standard';

export {
ApiVersion,
Expand All @@ -21,6 +27,10 @@ export {
GraphQLError,
StorefrontApiVersion,
SubscribableSignalLike,
AppEventAttributeValue,
AppEventAttributes,
AppEventEmitResult,
AppEvents,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ToastApi,
Intents,
SubscribableSignalLike,
AppEvents,
} from '../shared';

import type {ExtensionTarget} from '../../extension-targets';
Expand Down Expand Up @@ -78,6 +79,11 @@ export interface StandardApi<Target extends ExtensionTarget = ExtensionTarget> {
*/
sessionToken: SessionToken;

/**
* Reports events to Shopify for this app.
*/
appEvents: AppEvents;

/**
* Tracks custom events and sends visitor information to [web pixels](/docs/apps/build/marketing-analytics/pixels). Use `publish()` to emit events and `visitor()` to submit visitor data.
*
Expand Down
Loading