/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->session->has($this->sessionKey)) {
         $this->googleTagManager->set($this->session->get($this->sessionKey));
     }
     $response = $next($request);
     $this->session->flash($this->sessionKey, $this->googleTagManager->getFlashData());
     return $response;
 }
 /**
  * Register the application services.
  */
 public function register()
 {
     $this->app['googletagmanager'] = $this->app->share(function ($app) {
         $googleTagManager = new GoogleTagManager($app['config']->get('googletagmanager::id'));
         if ($app['config']->get('googletagmanager::enabled') === false) {
             $googleTagManager->disable();
         }
         return $googleTagManager;
     });
     $this->app->bind('Spatie\\GoogleTagManager\\GoogleTagManager', 'googletagmanager');
 }
 /**
  * Register the application services.
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/../resources/config/config.php', 'googletagmanager');
     $googleTagManager = new GoogleTagManager(config('googletagmanager.id'));
     if (config('googletagmanager.enabled') === false) {
         $googleTagManager->disable();
     }
     $this->app->instance('Spatie\\GoogleTagManager\\GoogleTagManager', $googleTagManager);
     $this->app->alias('Spatie\\GoogleTagManager\\GoogleTagManager', 'googletagmanager');
     if (is_file(config('googletagmanager.macroPath'))) {
         include config('googletagmanager.macroPath');
     }
 }
 /**
  * Bind data to the view.
  *
  * @param View $view
  */
 public function create(View $view)
 {
     if ($this->googleTagManager->isEnabled() && empty($this->googleTagManager->id())) {
         throw new ApiKeyNotSetException();
     }
     $view->with('enabled', $this->googleTagManager->isEnabled())->with('id', $this->googleTagManager->id())->with('dataLayer', $this->googleTagManager->getDataLayer());
 }