# How to set up In-app analytics

**URL:** <https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533>\
**Category:** Technical Support\
**Created:** [October 27, 2021, 2:06pm UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533 "2021-10-27T14:06:01Z")\
**Posts on this page:** 8\
**Page:** 4

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [December 22, 2021, 11:03am UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/63 "2021-12-22T11:03:43Z")

</div>

You have a target that should count all contacts with `type: "person"` regardless of their reports, and it is still showing up as zero. So, let’s try to solve it first before moving into targets that depend on reports.

Can you please make sure of these things?

- the user who is looking at the target should also be able to see the contacts (patients) in the People tab
- the patient contact doc should have `type: "person"`

If the above conditions are met, please look in the [browser console](https://developer.chrome.com/docs/devtools/open/#console) to see if there are any errors reported when you open the targets tab.

---

<div class="post-metadata">

**Author:** ![oyierphil](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/oyierphil/32/946_2.png) [@oyierphil](https://forum.communityhealthtoolkit.org/u/oyierphil)\
**Post date:** [December 22, 2021, 11:20am UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/64 "2021-12-22T11:20:16Z")

</div>

@binod  
My target.js file with \* the patient contact doc with `type: "person"`

```auto
const extras = require('./nools-extras');

const {
  posCovidPercTested,
  negCovidPercTested,
  pendCovidPercTested,
} = extras; 

module.exports = [  
  {
    id: 'Covid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.Covid.title',
    subtitle_translation_key: 'targets.all_time.subtitle',
    appliesTo: 'reports',
    appliesToType:['person'],
    date:'now',
    idType: 'contact'
   },

  {
    id: 'posCovid-test-this-month',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.posCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf:posCovidPercTested, 
    date: 'now',
  },

  {
    id: 'negCovid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.negCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf: negCovidPercTested,
    date:'now',
  },
  
  {
    id: 'pendCovid-test-all-time',
    type: 'count',
    icon: 'medic-covid-case',
    goal: -1,
    translation_key: 'targets.pendCovid.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'contacts',
    appliesToType:['person'],
    appliesIf: pendCovidPercTested,
    date:'now',
  },

];

```

I have seen browser errors as below:

 ![browser console log](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/b/b3b5083d5e1187531c1cbce1dd7386c74f29dae6.png)  
 ![browser console log_2](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/9/929bb595abc1784532e671bdb3e4677c3e08897c.png)  
 ![browser console log_3](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/5/5f00ee81f02d9f6f62493f82d17dfae69a328cfb.png)

---

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [December 22, 2021, 11:24am UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/65 "2021-12-22T11:24:03Z")

</div>

> [@oyierphil](#):
>
> {  
> id: ‘Covid-test-all-time’,  
> type: ‘count’,  
> icon: ‘medic-covid-case’,  
> goal: -1,  
> translation\_key: ‘targets.Covid.title’,  
> subtitle\_translation\_key: ‘targets.all\_time.subtitle’,  
> appliesTo: ‘reports’,  
> appliesToType:[‘person’],  
> date:‘now’,  
> idType: ‘contact’  
> }

Can you please update your first target to have `appliesTo: 'contacts'`, instead of `reports`?:

```js
{
id: 'Covid-test-all-time',
type: 'count',
icon: 'medic-covid-case',
goal: -1,
translation_key: 'targets.Covid.title',
subtitle_translation_key: 'targets.all_time.subtitle',
appliesTo: 'contacts',
appliesToType:['person'],
date:'now',
idType: 'contact'
}

```

---

<div class="post-metadata">

**Author:** ![oyierphil](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/oyierphil/32/946_2.png) [@oyierphil](https://forum.communityhealthtoolkit.org/u/oyierphil)\
**Post date:** [December 22, 2021, 11:32am UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/66 "2021-12-22T11:32:46Z")

</div>

@binod  
The target file on the server reads as above at attached

![Target file](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/3/31967f19e1f4f255c0c390ca5fa74584f41d1e79.png)

Wondering the issue with translations, we didn’t change the file, we however added some fields, especially screening component and the extra tests

---

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [December 22, 2021, 4:57pm UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/67 "2021-12-22T16:57:23Z")

</div>

> [@binod](#):
>
> the patient contact doc should have `type: "person"`

After looking at your config (thanks for the access), it looks like your `contact_types` section in the `app_settings.json` file does not have a contact type having `id: "person"`.

So please change the targets `appliesToType` to include something that is in your contact types. You can specify multiple contact types there.

Then please create some contacts matching the contact type specified. After you log in as an offline user who can see the contact just created, your first target should show a number greater than zero.

---

<div class="post-metadata">

**Author:** ![oyierphil](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/oyierphil/32/946_2.png) [@oyierphil](https://forum.communityhealthtoolkit.org/u/oyierphil)\
**Post date:** [December 22, 2021, 6:33pm UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/68 "2021-12-22T18:33:05Z")

</div>

@binod  
I had noted that we don’t have a contact\_type person, the reason I changed to contact instead of person

Our hierarchy is two level, a national office ( **DHARC-JKUAT** ) and four county offices ( **DHARC-KJD, DHARC-MKS, DHARC-NRB and DHARC KBU** )

I’m trying to edit the contact type from another form to capture the hierarchy above, any ideas?

```auto
{
      "id": "person",
      "name_key": "contact.type.person",
      "group_key": "contact.type.person.plural",
      "create_key": "contact.type.person.new",
      "edit_key": "contact.type.person.edit",
      "primary_contact_key": "clinic.field.contact",
      "parents": [
        "district_hospital",
        "health_center",
        "clinic"
      ],
      "icon": "medic-person",
      "create_form": "form:contact:person:create",
      "edit_form": "form:contact:person:edit",
      "person": true
    }
  ],

```

---

<div class="post-metadata">

**Author:** ![binod](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/binod/32/60_2.png) [@binod](https://forum.communityhealthtoolkit.org/u/binod)\
**Post date:** [December 23, 2021, 4:27am UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/69 "2021-12-23T04:27:47Z")

</div>

The two levels you have mentioned (national office and county offices) represent the places.

1. What are the contact types that represent people?
2. Which contact types do you want to count in the first target?
3. When you log in as an offline user, do the contacts appear in the People/Home tab?

---

<div class="post-metadata">

**Author:** ![oyierphil](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/oyierphil/32/946_2.png) [@oyierphil](https://forum.communityhealthtoolkit.org/u/oyierphil)\
**Post date:** [January 4, 2022, 7:48pm UTC](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533/70 "2022-01-04T19:48:43Z")

</div>

Happy New Year Colleagues  
Thank you @binod for the support, its been a working holiday, our targets are now up and running as below:

 ![Target Display_Prod Server_3](https://communityhealthtoolkit.b-cdn.net/uploads/default/original/2X/4/4a0adc33e0aa9c4f6d0d0d3c0e91c997bcad5995.png)  
I summarize our experiences as below:

1. We had picked the wrong contact type to represent the values we wanted to count, and this was sorted by going back to the app settings and reviewing the same. Our functions were not communicating with the back-end, the reason no data was displayed, and we sorted this by specifying the correct contact type
2. We also had used the wrong type for **date:‘reported’** without specifying the dates of interest, **date:‘now’** did the work and summarized all our target values.
3. We realized that the data downloaded was missing the field we wanted to build targets for. Using Fauxton ([https://localhost/\_utils/](https://localhost/_utils/)), we managed to access the report of interest and include the missing field. By running queries with Mango” in the left pane of Fauxton, it was possible to see which fields had data and which ones were affected by revisions, further making it possible to specify the report fields in the function definitions

Current challenge is now to display target data per place, four places as level 2 hierarchy, will update once it is sorted

[Previous page](https://forum.communityhealthtoolkit.org/t/how-to-set-up-in-app-analytics/1533.md?page=3)
