Using Tracker searchTarget in dataview

Hi guys,

I use the Tracker-Plugin to log some habits, body or mental issues, like my stress_level in my daily notes.
To log it (from 0-10), I use the value-attached tag field:

#log/dailyQuestions/stress_level:5 

(=> if I have a medium stress level, like 5 on a scale from 0-10)

Now, additionally to the nice graph-view of the Tracker plugin, I want to analyze my log in a dataview-table, where I can add some more key-value-pairs to the daily notes (for example “stress_level_comment::”).

Here is my question:
Is it possible to analyze the value-attached tag field from above in a dataview?

I tried this, but it didn’t work:

```dataview
TABLE 
	log/dailyQuestions/stress_level, 
	stress_level_comment
From "Daily notes"
Where log/dailyQuestions/stress_level > 0
SORT file.name DESC
```

Thanks in advance,
kind regards,
Silias

How do you write that in your markdown? A tag can’t be given a value normally, and if it’s given a value it normally isn’t a tag, so what have you actually written in your notes?

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

1 Like

Hi Holroy,

thanks for your answer and your tip! :slight_smile:
=> I directly edited my original post, for better readability… :wink:

you asked, how I write that in markdown?
=>

#log/dailyQuestions/stress_level:5

As far as I understand, the tag #log/dailyQuestions/stress_level get the value 5 attached, see the doc of the tracker-plugin here

=> So, as I asked in my previous post: Do you think it’s possible to analyze the value-attached tag field from above in dataview, and if yes, how? :slight_smile:

To define a dataview field, you need to do one of these:

---
fieldA: myValueA
---
fieldB:: myValueB

Doing just #log/dailyQuestions/stress_level: 5 in the body text doesn’t define a dataview field, and can as such not be read from neither a dataview query, nor the tracker plugin.

So doing the following:

#log/dailyQuestions/stress_level:: 5

`$= dv.span( dv.current() ) `

In a file, reveals that the following are true:

  • It does make the #log/dailyQuestions/stress_level into a tag, as seen in both file.etags and file.tags
  • It creates a dataview field named: log/dailyQuestions/stress_level with a value of 5
  • It normalises and created a dataview field named: logdailyquestionsstress_level with a value of 5

Accessed from dataviewjs

Further more, if we try to access this as from a dataviewjs query:

with slashes as object field: `$= dv.span( dv.current().log/dailyQuestions/stress_level ) `
with slashes as reference: `$= dv.span( dv.current()["log/dailyQuestions/stress_level"] ) `
normalised: `$= dv.span( dv.current().logdailyquestionsstress_level ) `

we get the output:

Notice how the first variant doesn’t work since it contains slashes, and they are not very good to include in a field name.

Accessed from a DQL query

However, you used a DQL query in your original post, and then either of these incantations would work to get the value of it:

```dataview
TABLE row["log/dailyQuestions/stress_level"], logdailyquestionsstress_level, stress_level_comment
TABLE 
	log/dailyQuestions/stress_level, 
	stress_level_comment
FROM "Daily notes"
SORT file.name DESC
```

NB! I simplified the query here, but do use your original query just correct with the new variant to get the actual field value.

So I guess that if you want to use it with the Tracker plugin, you probably should use the logdailyquestionsstress_level variant, and in a DQL query, you could use either. I tend to see the row["..."] variant as slightly more readable. (And even better would be to use a better field name without the slashes)


In summary, to make it a proper field in the body of your note you need to use two colons. And then to refer to it you need either to use the normalised variant, logdailyquestionsstress_level, or the row["log/dailyQuestions/stress_level"] to get the value of it. And I reckon you’ll need to use the first variant within Tracker definitions.

Hi Holroy,

thank you very much for your detailed answer!!! :slight_smile:

you wrote:

Doing just #log/dailyQuestions/stress_level: 5 in the body text doesn’t define a dataview field, and can as such not be read from neither a dataview query, nor the tracker plugin.

and advised me to use the double-colon Syntax instead, like

#log/dailyQuestions/stress_level:: 5

… but in the tracker-doc, it says:

a value can be attached to the tag in the format of '#tagName:value '. Note the value should be appended right after your tag and an extra colon without spaces

so when I write:
#log/dailyQuestions/stress_level:5 the value “5” is attached to my hashtag “#log/dailyQuestions/stress_level” and I can plot it with this tracker-query:

```tracker
searchType: tag
searchTarget: log/dailyQuestions/stress_level
startDate: 2023-02-01 Wed
endDate: 
line:
 title: Stresslevel
 yAxisLabel: Rating
 yMin: 0
 yMax: 10
```

it works fine…

But your are right!
Thanks for the tipp with that dataviewjs-query `$= dv.span( dv.current() ) ` to show all dataview-fields of the current file! Awesome!! :slight_smile:
I played around with it a little bit, and yes, as you already mentioned, there will only be a dataview-field created, if you use the double-colon…

So probably the tracker-plugin uses a different Syntax as the dataview-plugin, or why do you think would the tracker-plugin work with only one colon?

It surely seems like the Tracker plugin does all of its variable lifting internally, and not using any other plugins or common scheme. So in this regards, I’m sorry I suggested/assumed it actually used Dataview’s format (and/or code).

My test files and queries

If you want to take a look at my test setup, extract the following zip into some folder (and you might possibly need to change the date format to “YYYY-MM-DD”)
TrackerVsDataview2.zip (1.8 KB)

So with some more testing I can reveal the following:

Case searchType searchTarget Comment Tracker Dataview
A tag log/dailyQuestions/stress_level One colon OK no
B tag "#log/dailyQuestions/stress_level One colon no
C frontmatter mood Not detected if in body OK(?) OK
D dvField moody Not detected if in frontmatter OK(?) OK
E dvField log/dailyQuestions/field Two colons No OK
F dvField #log/dailyQuestions/field” Two colons OK(?) no

Note that for cases “A” and “B” if you add a space after the single colon, the value isn’t detected anymore. Tracker doesn’t detect case “C” if it’s not in the frontmatter, and similar it doesn’t detect “D” if that’s written in the frontmatter. Dataview allows for field to be defined in either the frontmatter or the body (although if you really want to you can limit to check for those within file.frontmatter)

For case “E” and “F” I retried the tag variants with double colon, only to see that now Tracker doesn’t detect it if using the dvField without the hashtag, see case “E”. But with case “F” it detects it as a dvField when including the hashtag. Dataview on the other does never include the hashtag in the field name, and also adds normalised names to the files, e.g. logdailyquestionsfield


In short, Tracker seems to implement its own collection of the various fields/tags and so on, and it doesn’t follow the same rules for collection as Dataview (even for the dvField stuff). If you’re using a tag with a value, you can’t add a space after the single colon, or else it’ll loose out on the value. If using frontmatter or dvField they’ll have to stay in that section for it work with Tracker.

1 Like

To answer your original question, to get something working in both Tracker and Dataview I would suggest changing to:

#log/dailyQuestions/stress_level:: 5

which would allow Tracker to get it through:

searchType: dvField
searchTarget: "#log/dailyQuestions/stress-level"

And Dataview through either of the following:

row["log/dailyQuestions/stress-level"]
logdailyquestionsstress_level

So the query would become something like:

```dataview
TABLE 
	logdailyquestionsstress_level, 
	stress_level_comment
From "Daily notes"
Where logdailyquestionsstress_level > 0
SORT file.name DESC
```
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.