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 and the account object documentation.

Account Profiles was retired in August 2024. For more information, see Personalization Account Profiles Retirement.

Important

Use onActionEvent in the global Configuration 

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

SalesforceInteractions Namespace
1global: {
2onActionEvent: (actionEvent) => {
3    const email = SalesforceInteractions.cashDom("header.logged-in-user-email").text().trim();
4    if (email) {
5    actionEvent.user = actionEvent.user || {};
6    actionEvent.user.attributes = actionEvent.user.attributes || {};
7    actionEvent.user.attributes.emailAddress = email;
8    }
9    return actionEvent;
10};
11}
Evergage Namespace
1global: {
2onActionEvent: (actionEvent) => {
3    const email = Evergage.cashDom("header.logged-in-user-email").text().trim();
4    if (email) {
5    actionEvent.user = actionEvent.user || {};
6    actionEvent.user.attributes = actionEvent.user.attributes || {};
7    actionEvent.user.attributes.emailAddress = email;
8    }
9    return actionEvent;
10};
11}

Use onActionEvent in the pageTypes Configuration 

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

SalesforceInteractions Namespace
1pageTypes: [
2    {
3        name: "search",
4        isMatch: () => /\/search/.test(window.location.pathname),
5        onActionEvent: (actionEvent) => {
6            const searchTerm = SalesforceInteractions.cashDom(".content.searchTerm").text().trim();
7            if (searchTerm) {
8                actionEvent.user = actionEvent.user || {};
9                actionEvent.user.attributes = actionEvent.user.attributes || {};
10                actionEvent.user.attributes.lastSearchTerm = searchTerm;
11            };
12            return actionEvent;
13        }
14    },
15],
Evergage Namespace
1pageTypes: [
2    {
3        name: "search",
4        isMatch: () => /\/search/.test(window.location.pathname),
5        onActionEvent: (actionEvent) => {
6            const searchTerm = Evergage.cashDom(".content.searchTerm").text().trim();
7            if (searchTerm) {
8                actionEvent.user = actionEvent.user || {};
9                actionEvent.user.attributes = actionEvent.user.attributes || {};
10                actionEvent.user.attributes.lastSearchTerm = searchTerm;
11            };
12            return actionEvent;
13        }
14    },
15],

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 documentation.

SalesforceInteractions Namespace
1global: {
2    listeners: [
3        SalesforceInteractions.listener("submit", "form.footer", () => {
4            const email = SalesforceInteractions.cashDom("form.footer input.email").val();
5            const name = SalesforceInteractions.cashDom("form.footer input.name").val();
6            SalesforceInteractions.sendEvent({
7                interaction: {
8                    name: "Form Submission | Footer",
9                },
10                user: {
11                    identities: {
12                        emailAddress: email
13                    },
14                    attributes: {
15                        name: name
16                    }
17                }
18            });
19        })
20    ]
21},
Evergage Namespace
1global: {
2    listeners: [
3        Evergage.listener("submit", "form.footer", () => {
4            const email = Evergage.cashDom("form.footer input.email").val();
5            const name = SalesforceInteractions.cashDom("form.footer input.name").val();
6            Evergage.sendEvent({
7                action: "Form Submission | Footer",
8                user: {
9                    attributes: {
10                        emailAddress: email,
11                        name: name
12                    }
13                }
14            });
15        })
16    ]
17},

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.

SalesforceInteractions Namespace
1pageTypes: [
2	{
3		name: "preferences",
4		isMatch: () => /\/preferences/.test(window.location.pathname),
5		interaction: {
6			name: "Preferences"
7		},
8		listeners: [
9			SalesforceInteractions.listener("submit", "form.user-prefs", () => {
10				const email = SalesforceInteractions.cashDom("form.user-prefs input.email").val();
11				const name = SalesforceInteractions.cashDom("form.user-prefs input.name").val();
12				SalesforceInteractions.sendEvent({
13					interaction: {
14						name: "Form Submission | Preferences",
15					},
16					user: {
17						identities: {
18							emailAddress: email
19						},
20						attributes: {
21							name: name
22						}
23					}
24				});
25			})
26		]
27	},
28],
Evergage Namespace
1pageTypes: [
2    {
3        name: "preferences",
4        isMatch: () => /\/preferences/.test(window.location.pathname),
5        listeners: [
6            Evergage.listener("submit", "form.user-prefs", () => {
7                const email = Evergage.cashDom("form.user-prefs input.email").val();
8                const name = SalesforceInteractions.cashDom("form.user-prefs input.name").val();
9                Evergage.sendEvent({
10                    action: "Form Submission | Preferences",
11                    user: {
12                        attributes: {
13                            emailAddress: email,
14                            name: name
15                        }
16                    }
17                });
18            })
19        ]
20    },
21],

Capturing account attributes works the same way as capturing user attributes. For the full structure of the account object, see the account object documentation.

SalesforceInteractions Namespace
1global: {
2    listeners: [
3        SalesforceInteractions.listener("submit", "form.survey", () => {
4            const industry = SalesforceInteractions.cashDom("form.survey input.industry").val();
5            const employeeSize = SalesforceInteractions.cashDom("form.survey input.employeeSize").val();
6            SalesforceInteractions.sendEvent({
7                interaction: {
8                    name: "Form Submission",
9                },
10                account: {
11                    attributes: {
12                        industry: industry,
13                        employeeSize: employeeSize
14                    }
15                }
16            });
17        })
18    ]
19},
Evergage Namespace
1global: {
2    listeners: [
3        Evergage.listener("submit", "form.survey", () => {
4            const industry = Evergage.cashDom("form.survey input.industry").val();
5            const employeeSize = Evergage.cashDom("form.survey input.employeeSize").val();
6            Evergage.sendEvent({
7                action: "Form Submission",
8                account: {
9                    attributes: {
10                        industry: industry,
11                        employeeSize: employeeSize
12                    }
13                }
14            });
15        })
16    ]
17},

See Also