You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A couple of weeks ago I remembered it would be super cool to have the real-time visitors of my website directly on my MacBook Pro Touch Bar, so I decided to do it.
First step: the API
I used Next.JS to draft a simple API endpoint that gets the data from Google Analytics and replies in JSON with the data I want to consume on the Touch Bar, already in the correct structure.
If you have questions about Google APIs authentication, this post can be useful.
Second step: Apple Script
I used a little tool called JSON Helper available in the Mac App Store for free and which allows to consume JSON files in Apple Scripts.
tell application "JSON Helper"
set json to fetch JSON from "https://myapi.com/api/analytics"
set users to realtime of json
set final to "" & users & " users"
end tell
This script fetches the URL and prints the number to the screen with the word users.
Third step: Adding to the Touch Bar
I've been using MTMR (My Touchbar My Rules) to customize my Touch Bar. The application uses a JSON description file to add different buttons and informations to the Touch Bar. I used a block called appleScriptTitledButton which executes the Apple Script in the source attribute in an interval defined in the refreshInterval attribute. In this case, I used 10 seconds since the Google Analytics API has some limits. Also, when I click the button with the real-time users it automatically opens the Google Analytics website on my preferred browser.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
A couple of weeks ago I remembered it would be super cool to have the real-time visitors of my website directly on my MacBook Pro Touch Bar, so I decided to do it.
First step: the API
I used Next.JS to draft a simple API endpoint that gets the data from Google Analytics and replies in JSON with the data I want to consume on the Touch Bar, already in the correct structure.
To do this I used the
googleapis
package and created the credentials here.If you have questions about Google APIs authentication, this post can be useful.
Second step: Apple Script
I used a little tool called JSON Helper available in the Mac App Store for free and which allows to consume JSON files in Apple Scripts.
This script fetches the URL and prints the number to the screen with the word users.
Third step: Adding to the Touch Bar
I've been using MTMR (My Touchbar My Rules) to customize my Touch Bar. The application uses a JSON description file to add different buttons and informations to the Touch Bar. I used a block called
appleScriptTitledButton
which executes the Apple Script in thesource
attribute in an interval defined in therefreshInterval
attribute. In this case, I used 10 seconds since the Google Analytics API has some limits. Also, when I click the button with the real-time users it automatically opens the Google Analytics website on my preferred browser.If you have any question let me know on Twitter.
Beta Was this translation helpful? Give feedback.
All reactions