# Capture User and Account Attributes

The `onActionEvent` method captures user and account attributes to add user data to an event before sending it to Personalization. For more information on the `user` and `account` objects, see the [user object](/docs/marketing/personalization/guide/event-options-salesforceinteractions.md#the-user-object) and the [account object](/docs/marketing/personalization/guide/event-options-salesforceinteractions.md#the-account-object) documentation.

:::important
Account Profiles was retired in August 2024. For more information, see [Personalization Account Profiles Retirement](https://help.salesforce.com/s/articleView?id=001744617\&type=1).
:::

## Use onActionEvent in the global Configuration

The following are examples of using the `onActionEvent` method in the `global` configuration.

```sfdocs-code {"lang":"javascript", "title": "SalesforceInteractions Namespace"}
global: {
onActionEvent: (actionEvent) => {
    const email = SalesforceInteractions.cashDom("header.logged-in-user-email").text().trim();
    if (email) {
    actionEvent.user = actionEvent.user || {};
    actionEvent.user.attributes = actionEvent.user.attributes || {};
    actionEvent.user.attributes.emailAddress = email;
    }
    return actionEvent;
};
}
```

```sfdocs-code {"lang":"javascript", "title": "Evergage Namespace"}
global: {
onActionEvent: (actionEvent) => {
    const email = Evergage.cashDom("header.logged-in-user-email").text().trim();
    if (email) {
    actionEvent.user = actionEvent.user || {};
    actionEvent.user.attributes = actionEvent.user.attributes || {};
    actionEvent.user.attributes.emailAddress = email;
    }
    return actionEvent;
};
}
```

## Use onActionEvent in the pageTypes Configuration

The following are examples of using the `onActionEvent` method in the `pageTypes` configuration.

```sfdocs-code {"lang":"javascript", "title": "SalesforceInteractions Namespace"}
pageTypes: [
    {
        name: "search",
        isMatch: () => /\/search/.test(window.location.pathname),
        onActionEvent: (actionEvent) => {
            const searchTerm = SalesforceInteractions.cashDom(".content.searchTerm").text().trim();
            if (searchTerm) {
                actionEvent.user = actionEvent.user || {};
                actionEvent.user.attributes = actionEvent.user.attributes || {};
                actionEvent.user.attributes.lastSearchTerm = searchTerm;
            };
            return actionEvent;
        }
    },
],
```

```sfdocs-code {"lang":"javascript", "title": "Evergage Namespace"}
pageTypes: [
    {
        name: "search",
        isMatch: () => /\/search/.test(window.location.pathname),
        onActionEvent: (actionEvent) => {
            const searchTerm = Evergage.cashDom(".content.searchTerm").text().trim();
            if (searchTerm) {
                actionEvent.user = actionEvent.user || {};
                actionEvent.user.attributes = actionEvent.user.attributes || {};
                actionEvent.user.attributes.lastSearchTerm = searchTerm;
            };
            return actionEvent;
        }
    },
],
```

## Setting User and Account Attributes Using Event Listeners

In the following code samples, the `onActionEvent` method is used in the `global` configuration. It listens on every page for a form in the footer to be submitted. It then sends an event containing the user's ID and captures the user's email address, which you can then configure for use as an identity. To know more about using captured data as an ID, see the [Event API](/docs/marketing/personalization/guide/event-options-salesforceinteractions.md#the-user-object) documentation.

```sfdocs-code {"lang":"javascript", "title": "SalesforceInteractions Namespace"}
global: {
    listeners: [
        SalesforceInteractions.listener("submit", "form.footer", () => {
            const email = SalesforceInteractions.cashDom("form.footer input.email").val();
            const name = SalesforceInteractions.cashDom("form.footer input.name").val();
            SalesforceInteractions.sendEvent({
                interaction: {
                    name: "Form Submission | Footer",
                },
                user: {
                    identities: {
                        emailAddress: email
                    },
                    attributes: {
                        name: name
                    }
                }
            });
        })
    ]
},
```

```sfdocs-code {"lang":"javascript", "title": "Evergage Namespace"}
global: {
    listeners: [
        Evergage.listener("submit", "form.footer", () => {
            const email = Evergage.cashDom("form.footer input.email").val();
            const name = SalesforceInteractions.cashDom("form.footer input.name").val();
            Evergage.sendEvent({
                action: "Form Submission | Footer",
                user: {
                    attributes: {
                        emailAddress: email,
                        name: name
                    }
                }
            });
        })
    ]
},
```

The following examples depict a listener in the `pageTypes` configuration. You can see that the event's structure is the same as the structure of the event sent by the listener in the `global` configuration in the previous namespace-specific examples.

```sfdocs-code {"lang":"javascript", "title": "SalesforceInteractions Namespace"}
pageTypes: [
	{
		name: "preferences",
		isMatch: () => /\/preferences/.test(window.location.pathname),
		interaction: {
			name: "Preferences"
		},
		listeners: [
			SalesforceInteractions.listener("submit", "form.user-prefs", () => {
				const email = SalesforceInteractions.cashDom("form.user-prefs input.email").val();
				const name = SalesforceInteractions.cashDom("form.user-prefs input.name").val();
				SalesforceInteractions.sendEvent({
					interaction: {
						name: "Form Submission | Preferences",
					},
					user: {
						identities: {
							emailAddress: email
						},
						attributes: {
							name: name
						}
					}
				});
			})
		]
	},
],
```

```sfdocs-code {"lang":"javascript", "title": "Evergage Namespace"}
pageTypes: [
    {
        name: "preferences",
        isMatch: () => /\/preferences/.test(window.location.pathname),
        listeners: [
            Evergage.listener("submit", "form.user-prefs", () => {
                const email = Evergage.cashDom("form.user-prefs input.email").val();
                const name = SalesforceInteractions.cashDom("form.user-prefs input.name").val();
                Evergage.sendEvent({
                    action: "Form Submission | Preferences",
                    user: {
                        attributes: {
                            emailAddress: email,
                            name: name
                        }
                    }
                });
            })
        ]
    },
],
```

Capturing `account` attributes works the same way as capturing `user` attributes. For the full structure of the `account` object, see the [account object](/docs/marketing/personalization/guide/event-options-salesforceinteractions.md#the-account-object) documentation.

```sfdocs-code {"lang":"javascript", "title": "SalesforceInteractions Namespace"}
global: {
    listeners: [
        SalesforceInteractions.listener("submit", "form.survey", () => {
            const industry = SalesforceInteractions.cashDom("form.survey input.industry").val();
            const employeeSize = SalesforceInteractions.cashDom("form.survey input.employeeSize").val();
            SalesforceInteractions.sendEvent({
                interaction: {
                    name: "Form Submission",
                },
                account: {
                    attributes: {
                        industry: industry,
                        employeeSize: employeeSize
                    }
                }
            });
        })
    ]
},
```

```sfdocs-code {"lang":"javascript", "title": "Evergage Namespace"}
global: {
    listeners: [
        Evergage.listener("submit", "form.survey", () => {
            const industry = Evergage.cashDom("form.survey input.industry").val();
            const employeeSize = Evergage.cashDom("form.survey input.employeeSize").val();
            Evergage.sendEvent({
                action: "Form Submission",
                account: {
                    attributes: {
                        industry: industry,
                        employeeSize: employeeSize
                    }
                }
            });
        })
    ]
},
```

## See Also

- *Salesforce Help*: [Create a User Profile Object](https://help.salesforce.com/s/articleView?id=sf.mc_pers_user_profile_object_create.htm)
