Created
September 18, 2018 16:16
-
-
Save treetop1500/7149251fcb593ab3f04ff7a3ca86ffd9 to your computer and use it in GitHub Desktop.
Easy Admin Controller Extension with Google Analytics Dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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