Introduction | laravel-analytics-go | Spatie       

 SPATIE  

laravel-analytics-go
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-analytics-go](https://spatie.be/docs/laravel-analytics-go/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-analytics-go/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/docs/laravel-analytics-go/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-analytics-go/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-analytics-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-analytics-go/v1/usage)
- [ Testing ](https://spatie.be/docs/laravel-analytics-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-analytics-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-analytics-go/v1/changelog)

  Laravel-analytics-go 
======================

 Retrieve Google Analytics data in Laravel Go 

### Useful links

- [Repository](https://github.com/spatie/laravel-analytics-go)
- [Discussions](https://github.com/spatie/laravel-analytics-go/discussions)

Introduction
------------

Using this package you can easily retrieve data from Google Analytics in Laravel Go.

```
period, err := analytics.Days(7, date.Now(r))
if err != nil {
    return web.Fail(err)
}

pages, err := analytics.From(r).FetchMostVisitedPages(r, period)
if err != nil {
    return web.Fail(err)
}
return web.JSON(pages)
```

`r` is the handler's `*web.Request`. Import this package as `analytics`, `go.laravel.com/date`, and `go.laravel.com/web`. Jobs, listeners and commands pass their `context.Context` instead.

Most methods return `[]analytics.Row`. Each row is a map keyed by Google's dimension and metric names. Known counts become `int64`, `date` becomes `time.Time` at UTC midnight, and other values stay strings.

Start with [installation and setup](installation-and-setup), then read [usage](usage). The Go port preserves the PHP package's report columns, limits and descending date order. Realtime uses an explicit minute range instead of converting calendar dates into minutes.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
