Easily create and log custom interactions on your managed package using Apex. As subscribers interact with your package and your Apex code is executed, the custom interactions that you defined are logged. Retrieve your custom interactions in your package’s AgentExchange App Analytics usage logs and usage summaries.
Required Editions
Available in: both Salesforce Classic and Lightning Experience
Available in: Enterprise, Performance, Unlimited, and Developer Editions
As an ISV partner, the complex features that you develop in your managed packages could involve multiple actions on different objects, callouts to Apex functions, and much more. It can be difficult to interpret how your subscribers interacted with specific packaged components via your downloaded App Analytics package usage logs and summaries.
To provide you with more clarity about your subscribers’ events in custom ways and at different granularity levels, create custom interactions in your managed packages using Apex.
With Apex custom interactions, you can discover:
Which app feature a user interacted with
How users flowed through a specific user journey
Which UI components a user interacted with
Keep these considerations in mind:
A custom interaction can appear for a given user request up to 50 times. This limit avoids flooding the logs due to large loops.
We recommend that you don’t call IsvPartners.AppAnalytics.logCustomInteraction from inside a loop.
If the IsvPartners.AppAnalytics.logCustomInteraction method is called from a running Apex test, no AgentExchange App Analytics package usage log or package usage summary data is produced.
Create and log custom interactions with your managed package using Apex.
Log Custom Interactions
Create and log custom interactions with your managed package using Apex.
In your packaged Apex code, include Apex enums that are associated with the events that you want to log as custom interactions.
In your Apex code, invoke IsvPartners.AppAnalytics.logCustomInteraction, using the enums that you created.
Test your code by running it in your development environment and checking your debug logs to be certain that the custom interactions you created are being logged. Ensure that your debug log levels for Apex Code are set to FINE.
After you’re finished with your implementation, publish a new version of your managed package.
After subscribers install your package, retrieve your package usage logs and package usage summaries. Filter your package usage log data on custom_entity_type by CustomInteractionLabel, and on log_record_type by CustomInteraction. Or filter your package usage summary data on custom_entity_type by CustomInteractionLabel.
Analyze your custom interaction data.
Example
Let’s suppose you have a Lightning Web Component (LWC). Your LWC provides a list of related contacts for each Account record, uses a table layout, and is wired to an Apex class. You add a new card layout to your LWC. To track how well users are adopting this new layout, you log an interaction when a user switches between layouts.
In your code, include Apex enums and invoke IsvPartners.AppAnalytics.logCustomInteraction.
1public class LogContactListInteraction {2 public Enum ContactListLayouts { TABLE, CARD }34 @AuraEnabled5 public static void log(String type) {6 try {7 IsvPartners.AppAnalytics.logCustomInteraction(getInteractionLabel(type));8 } catch (Exception e) {9 throw new AuraHandledException(e.getMessage());10 }11 }1213 private static ContactListLayouts getInteractionLabel(String type) {14 if (type.toLowerCase() == 'table') {15 return ContactListLayouts.TABLE;16 } else if (type.toLowerCase() == 'card') {17 return ContactListLayouts.CARD;18 }19 return null;20 }21}
Next, you test your code. With your Apex code debug log level set to FINE, confirm that the custom interactions are logged by finding events in your debug logs called APP_ANALYTICS_FINE, APP_ANALYTICS_WARN, or APP_ANALYTICS_ERROR.
1APP_ANALYTICS_FINE [External]IsvPartners.AppAnalytics.logCustomInteraction was called, but not from an installed managed package.2This means that the code is ready to be packaged.