- A Laravel 5 package used to list your top articles by date.
- Uses Google Analytics API.
- Go to: https://console.developers.google.com/apis/credentials
- Create credentials
- Service account key
- New service account
- Put the name, select JSON and Create!
- Open the downloaded file.
- Copy the e-mail at "client_email".
- Go to: https://analytics.google.com
- Admin
- Select your account and go to User Management
- Paste the e-mail on the input and Add!
- Now copy the JSON file to your project.
composer require "ruwer/toparticles":"dev-master"
Add to your config/app.php:
'providers' => [
//...
Ruwer\TopArticles\TopArticlesServiceProvider::class,
],
and:
'aliases' => [
//...
'TopArticles' => Ruwer\TopArticles\TopArticlesFacade::class,
],
In your terminal:
php artisan vendor:publish --provider="Ruwer\TopArticles\TopArticlesServiceProvider"
composer dump-autoload
Now open the file: config/analytics.php and configure the path of your JSON file generated by Google Analytics.
In your controller:
use TopArticles;
TopArticles::get(
"ga:xxxxxxxx", //Your Google Analytics Profile ID
"7daysAgo", //Begin Date
"today", //End date (you can also use Y-m-d)
"(articles/)", //Regex for Filters (everything containing "articles/")
10 //Results
);
//It'll return an array with your top viewed articles :)