Custom Code to Count Activities

I would suggest doing this using the Hubspot engagements calls API utilising the search endpoint: Accounts Dashboard | HubSpot

You can filter based on specific criteria that you are looking at for each call you want to count. ie, Call Status is completed, or a specific time frame you would like to look at, or specific users you want to track.

You can then extract the ‘total’ value from the api response which is a count of all the calls that match your search.

Here’s a little sample of how I’ve done it in the past:

const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {
const hubspotClient = new hubspot.Client({"accessToken":process.env.YOUR_SECRET});
var id = event.inputFields['id'];
const PublicObjectSearchRequest = {
 filterGroups: [
 {
 "filters":[
 {"propertyName":"associations.contact",
 "operator":"EQ",
 "value": id
 }
 // ADD ANY OTHER FILTERS YOU WOULD LIKE TO USE HERE. MAX OF 3 PER FILTER GROUP.
 ]
 }
 ],
 properties:[]
};
var count_of_calls;
try {
 const apiResponse = await hubspotClient.crm.objects.emails.searchApi.doSearch(PublicObjectSearchRequest);
 count_of_calls = apiResponse.total
} catch (e) {
 console.log(e);
 throw e
}
 callback({
 outputFields: {
 count_of_calls: count_of_calls
 }
 });
}

You will obviously need to add your own secret key into this code, and add the contact record id as an input field.

Hope this helps!