Error calculating daily stats
I have commented out the use of Plausible to get the analytics:
However, I am getting an error every time the Daily Stats is calculated:
28 Replies
Hi @Ricardo Batista. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, it seems like you're having an issue with calculating daily stats in your Wasp application. However, the specific error you're encountering isn't directly addressed in the provided sources.
In the Discord support thread, a similar issue was discussed where a user was having trouble with the
calculateDailyStats
function. The community suggested checking the logs in the database if the job fails, and debugging the calculateDailyStats
function. They also suggested changing the job to run every minute in the main.wasp file for debugging purposes. However, this may not directly apply to your situation as your error seems to be related to getting metadata from a plugin.
Unfortunately, without more specific information related to your issue, it's difficult to provide a more precise solution. I would recommend checking the logs as suggested in the Discord thread, and possibly reaching out to the Wasp community for more specific guidance.
Here is the relevant source (https://discord.com/channels/686873244791210014/1215945587841831033) from the knowledge provided.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Just to complement - I have setup the env variables:
Oh that's a bit peculiar! @Vinny (@Wasp) any ideas?
Is it working if you uncomment plausible ?
Also doesnβt work
hm. maybe something changed since we pushed Open SaaS. I tested it and it worked, but because we use Plausible, I haven't seen the error
I'll have to play with it tomorrow and see
I decided to update the files to the latest ones, and got the following error as well (same as before, different message):
If I switch it to Plausible instead of GA, I get a normal error (because I don't have the Plausible credentials):
@Vinny (@Wasp) if you need credentials to test, happy to send you via DM
@Ricardo Batista Iβve been having this error since the first deployment but didnβt care that much because my app works just as intended (btw, Iβm using GA)
Gotcha, so it might happen to others as well πͺπ»
@jordi0lle @Ricardo Batista have you tried removing
/v1
from the PLAUSIBLE_BASE_URL
env var?
${PLAUSIBLE_BASE_URL}/v1/stats/aggregate?site_id=${PLAUSIBLE_SITE_ID}&metrics=pageviews
<-- there's a bug, and v1 will appear twice in the URL if notThe issue we have is with Google Analytics, not Plausible
Nope! Iβll try later on and see if tomorrow the error is there ππ»
@Vinny (@Wasp) did you have a chance to look at this?
Nope not yet. Sorry. I will make an issue and definitely check tomorrow
Any ideas what it might be?
Or where to start?
Not sure, it might just be the fact that you guys use Plausible and something changed in GA flow?
Yeah thatβs what I was thinking too
Ricardo, I don't have any problems using the google analytics when running the daily stats jonb
I think you're not setting up your google analytics correctly with your cookie consent banner
what I would suggest is
1) just add the google analytics tag to the
app.head
property of your main.wasp
file:
(make sure to add your Google Analytics ID in the two places specified below)
2) restart your wasp app and then check in browser's dev tools if you see the _ga
cookies (there should be at least two)
3) if that's working, then you know it's an issue with cookie consent banner. If not, go back and check the analyics docs and follow all the steps again to make sure you're setting up your analytics correctly (e.g. convert your key to base64 by copying the whole key echo -n "-----BEGIN PRIVATE KEY-----\nMIIE ... tQ+A==\n-----END PRIVATE KEY-----\n" | base64
)hey @Vinny (@Wasp) thanks!
I am not using OpenSaaS to fire the tag, given that I have other tags to fire - so I am relying on Google Tag Manager for the tag firing.
Nevertheless, the connection to GA should be done via the GA credentials in .env.server, correct?
yeah, so you'll have the GA ID which is in the script tag
and then you'll have to set up the API by adding the keys in
.env.server
it's all outlined in the docs but let me know if you get stuck
.env.server
The issue in having the script tag is that it would fire twice (one thru OpenSaaS, another thru GTM).
But I do have the key in
.env.server
:
This should be enough, right?it's weird because you have to go to the google cloud console and set it all up, then convert the private key to base64, then go to the analytics console and add the special email etc
is the script also in your
main.wasp
?
ah I see what you mean, if you add it, it would fire twice
but I don't think that would cause issues for testing, would it?
I don't know how Google Tag Manager works, so if you can test it out in app.head
and let me know what happens, then we can start checking off possible issuesBut it is weird that DailyStats needs to the GA tag to fire...
I have GTM tag in
main.wasp
:
How else would it be able to pull stats like page views if the script isnβt being added to the site?
Through GTM it also fires the tag - my point is that you don't need the tag to fire, you need access to the info in GA.
Yeah. Makes me think you didnβt convert your key correctly. Did you paste the entire key as a string, with the BEGINNING and ENDING comments?
Are you seeing activity on your google analytics dashboard
?
Yup, seeing data - but that's unrelated because it is done via GTM.
Just gave it a try at generating a new key, and same error:
checkout the top answer here https://stackoverflow.com/questions/74131595/error-error1e08010cdecoder-routinesunsupported-with-google-auth-library
try logging the key on line 4 in the googleAnalyticsUtils (
const PRIVATE_KEY = Buffer.from(process.env.GOOGLE_ANALYTICS_PRIVATE_KEY!, 'base64').toString('utf-8');
) and comparing it to the key in your JSON file
Your code is failing because the client is being set up with bad credentials. Most likely a corrupted private key.
this looks like the solution you're looking for: https://github.com/orgs/vercel/discussions/219#discussioncomment-128702
GitHub
Google Cloud Keyfile.json Β· vercel Β· Discussion #219
I am trying to authenticate with Google Cloud via a Next API route. GCP needs the path to the key JSON file. Not the values in the file, but the actual file. So links to tutorials re: base64 and se...
Man, this is so weird - there must be some small thing I am missing. When I log the key I get exactly the same... Let me send you in private the keys, maybe you can find it
Big thanks to @Vinny (@Wasp) for helping out!
Got it now, there were three things:
1. I had to use
const PRIVATE_KEY = JSON.parse(Buffer.from(process.env.GOOGLE_ANALYTICS_PRIVATE_KEY!, "base64").toString().replace(/\n/g,""))
as per this comment
2. I was encoding with single quotation marks, it should be echo -n ""-----BEGIN PRIVATE KEY---(...)"" | base64
3. I had to enable the Google Analytics Data API in Google Console
Maybe you guys can include this in the documentation for future reference?