Spotify Google Analytics API Issues

I’m attempting to integrate the Google Analytics API but I can’t seem to retrieve any data from it. Is there something I’m overlooking?

Here’s the code I’m currently using:

var gtrack = sp.require("sp://import/scripts/googletracker");
var tracker = new gtrack.GoogleTracker('UA–xxxxxxx–1');
tracker.track('APPNAME/modulename');

Thank you in advance for any assistance!

That code has nothing to do with Google Analytics - it’s old Spotify app platform syntax that died in 2017. For GA data, you need the Google Analytics Reporting API. I wasted weeks on this exact migration. First, create a Google Cloud Console project and enable the Analytics Reporting API. Then choose OAuth2 for user access or service accounts for server-to-server stuff. Authentication’s a pain - you’re dealing with access tokens and refresh cycles. After that, you’re making HTTP requests to analyticsreporting.googleapis.com with your view ID, metrics, and dimensions in the request body. Skip the raw HTTP calls though - Google’s client libraries save you from wrestling with all the nested objects and date range formatting.

Your problem is you’re using old Spotify app platform code that doesn’t work anymore. Spotify killed off sp.require and sp://import syntax when they scrapped their app platform years ago. To actually pull Google Analytics data, you’ll need the Google Analytics Reporting API v4 or the newer GA4 Data API. Set up a service account in Google Cloud Console, grab the JSON credentials file, and handle the OAuth2 flows. I hit this same wall migrating old analytics stuff. Here’s what helped: tracking events and pulling data are totally different processes with different API endpoints. Use Google’s official client libraries for whatever language you’re working in - they’ll handle most of the auth headaches for you. Double-check your Analytics account has API access permissions set up right, or you’ll get empty responses even when your code’s perfect.

That code tracks events TO Google Analytics, not retrieving data FROM the Analytics API. Completely different things.

To pull GA data, you need OAuth2 authentication, proper API client setup, and requests to reporting endpoints. Just the setup takes hours - credentials, token refresh, API quotas.

I hit this same wall last year building dashboards that needed GA data. Wasted tons of time on authentication flows and rate limiting.

Automating the whole process saved me. Now I have a workflow that handles OAuth, pulls data on schedule, and pipes it wherever needed. No more credential headaches or API complexity.

The workflow connects to GA, grabs whatever metrics I want, then pushes to databases, sends via webhooks, or triggers actions based on the numbers. 10 minutes to set up versus hours of coding.

yeah, that spotify code is totally outdated and not gonna work. you’re confusing sending data vs pulling data from GA. to get analytics data, you gotta use the right GA api with oauth setup. it’s a lot more complicated than what you’re doing.