Hi @lakshyakan,
your ProfileScript always returns only a value / string. No object.
It is possible to write from objects as strings - but probably too complex here. In addition, the UserProfile also has limits.
Maybe it makes more sense for you to divide the website into categories. In pages write directly attributes to the category - which you can read out via an activity and fill your profile with it accordingly.
I don't know for what you need such an exact count exactly. Maybe this is for example the Affinity Model which could fit for you: https://experienceleague.adobe.com/docs/target/using/audiences/visitor-profiles/category-affinity.ht...
Personally, I would rather recommend to collect such data in Adobe Analytics and / or via DataLayer Pushes. But less directly in Target - if that has a large scale.