4

Background: I have a managed package that is actively being used by other organizations. The end goal is to be able to appropriately pull app analytics from Salesforce so that I can better understand how folks are using my app.

I opened a case with Salesforce to appropriately enable app analytics. The case was reported to be appropriately worked about a week ago, so app analytics should be working now, and there should be data to query.


What I have tried so far:

After reviewing the documentation on AppAnalyticsQueryRequest: https://developer.salesforce.com/docs/atlas.en-us.220.0.object_reference.meta/object_reference/sforce_api_objects_appanalyticsqueryrequest.htm,

I tried to query the Salesforce SOAP API like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:PackageVersionHeader>
      </urn:PackageVersionHeader>
      <urn:QueryOptions>
      </urn:QueryOptions>
      <urn:SessionHeader>
         <urn:sessionId>[session id goes here]</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>SELECT DataType, DownloadExpirationTime, DownloadUrl, EndTime, ErrorMessage, LastReferencedDate, LastViewedDate, Name, OrganizationIds, PackageIds, RequestState, StartTime FROM AppAnalyticsQueryRequest</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

...but my query response is blank.

      <queryResponse>
         <result>
            <done>true</done>
            <queryLocator xsi:nil="true"/>
            <size>0</size>
         </result>
      </queryResponse>

My Question: What are the correct steps to get analytics data back?

Parallel posted to https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&id=9062I000000gBBTQA2


Now that I got it working, here are some troubleshooting lessons learned that I wish I had known:

  1. If you don’t specify an EndTime, the StartTime must be 7 days or fewer from today to avoid a limits error.
  2. You must specify values for either PackageIds or OrganizationIds. Both can’t be wildcard/blank.
  3. Values provided to OrganizationIds or PackageIds must use the 15-digit RecordID format.
  4. You can only run so many App Analytics queries per day against the same LMO (based on your license and such)
  5. CustomObjectUsageSummary doesn't work. Use CustomObjectUsageLog instead.
2

Salesforce documentation is really thin on this and there is lot of scope to make it clear.

Prerequisite

1.Log a case with Salesforce support to get this feature enabled in your LMO

2.Create a permission set with access to the AppAnalyticsQueryRequest object

Here are the steps to create AppAnalyticsQueryRequest .

1.Login to the workbench from your LMO (License Management Org)

2.Navigate to data insert for the AppAnalyticsQueryRequest

enter image description here

3.Fill in the required field details

enter image description here

The key here is you will need to specify either organizationId or the packageId. Both of them cannot be null.You can obtain the packageId from your packaging org.

Also for DataType use CustomObjectUsageLog.

CAUTION: Its not CustomObjectUsageSummary, instead use "CustomObjectUsageLog"

4.Insert the data. Now use the developer console to write a simple query like below

SELECT  ID, Downloadurl, DownloadExpirationTime, StartTime FROM AppAnalyticsQueryRequest

enter image description here

NOTE - It may take somewhere between 30minutes to 1 hour before you see the download url. (execute the query after an hour or so).Once you have the download url, visit the url to download the csv and analyze the data.

Troubleshooting Tips

Now that I got it working, here are some troubleshooting lessons learned:

  1. If you don’t specify an EndTime, the StartTime must be 7 days or fewer from today to avoid a limits error.
  2. You must specify values for either PackageIds or OrganizationIds. Both can’t be wildcard/blank.
  3. Values provided to OrganizationIds or PackageIds must use the 15-digit RecordID format.
  4. You can only run so many App Analytics queries per day against the same LMO (based on your license and such)
  5. CustomObjectUsageSummary doesn't work. Use CustomObjectUsageLog instead.
5
  • Thank you for your answer. Once I can verify that this works, I will mark it as the right answer. I don't see AppAnalyticsQueryRequest in my dropdown. Am I right to assume that I need to open a case with Salesforce to get that figured out? Sep 12 '19 at 23:34
  • 1
    Yes this means your LMO org does not have this feature enabled . Sep 12 '19 at 23:35
  • 1
    It ended up that the feature was enabled by Salesforce, but the account we were using for the LMO didn't have permissions to the object yet. As promised, I marked your answer, but Vanessa's answer was also super helpful. Sep 13 '19 at 17:37
  • 2
    Thank you for this answer! For anyone trying this out though, be sure to see @RobertHyatt's bullet points notes that he added to his original question (in particular: "CustomObjectUsageSummary doesn't work. Use CustomObjectUsageLog instead").
    – Anika
    Apr 7 '20 at 18:51
  • 1
    @Anika Improved the answer! Thank you Apr 7 '20 at 19:35
2

To begin with, after you have AppAnalytics activated, you should create a permission set in the org where you LMO is, in order to grant you (and other users) CRUD access to the AppAnalyticsQueryRequest object.

After that, you'll be submitting a record to the AppAnalyticsQueryRequest object, which should:

  1. Specify the DataType

  2. Have a StartTime and EndTime within the range of a week (EndTime is optional)

  3. Specify OrganizationIds (or if left blank it will be wildcard and consider all of your subscriber orgs that are active)

  4. Specify PackageIds (or if left blank it will be wildcard and consider all of your packages that are actived with AppAnalytics)

We recommend submitting the request through the CLI, for example: ~codey$ sfdx force:data:record:create -s AppAnalyticsQueryRequest -v “StartTime=2019-06-08T:12:00:00 EndTime=2019-06-12T12:00:00 DataType=CustomObjectUsageLog PackageIds=0331U000000EHq2”-u CodeysPBO

As a reference, this blog post will guide you step by step on how to get started: https://medium.com/inside-the-salesforce-ecosystem/get-app-smart-how-to-use-appexchange-app-analytics-bd0751c68ca6

Please let us know if you have any questions.

The Salesforce labs team also recently launched this app which works as a UI for your AppAnalytics request and can be installed in your org with your LMO: https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000G0nUXUAZ

2
  • Welcome to Salesforce SE! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Sep 13 '19 at 15:24
  • Thank you for calling out the issue with the permissionset. We did need to update our permissions to make it work. Sep 13 '19 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.