Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Created September 18, 2018 16:16
Show Gist options
  • Save treetop1500/7149251fcb593ab3f04ff7a3ca86ffd9 to your computer and use it in GitHub Desktop.
Save treetop1500/7149251fcb593ab3f04ff7a3ca86ffd9 to your computer and use it in GitHub Desktop.
Easy Admin Controller Extension with Google Analytics Dashboard
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Google_Client;
use Google_Service_AnalyticsReporting;
class AdminDashboardController extends AdminController
{
/**
* @Route("/dashboard", name="admin_dashboard")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Google_Exception
*/
public function dashboardAction(Request $request)
{
// Create the Google API Client and authorize it to retrieve
// analytics for the dashboard page.
$client = new Google_Client();
$KEY_FILE_LOCATION = $this->getParameter('kernel.project_dir') . '/XXXXX-YOUR-AUTH-FILE-XXXXX.json';
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->addScope(\Google_Service_AnalyticsReporting::ANALYTICS_READONLY);
$tokenArray = $client->fetchAccessTokenWithAssertion();
return $this->render('easy_admin/dashboard.html.twig', array(
"google_token" => $tokenArray['access_token']
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment