PHPackages                             jonasva/laravel-facebook-insights - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jonasva/laravel-facebook-insights

ActiveLibrary[API Development](/categories/api)

jonasva/laravel-facebook-insights
=================================

Facebook page insights integration with Laravel

262.1k4[2 issues](https://github.com/jonasva/laravel-facebook-insights/issues)PHP

Since Aug 10Pushed 10y ago5 watchersCompare

[ Source](https://github.com/jonasva/laravel-facebook-insights)[ Packagist](https://packagist.org/packages/jonasva/laravel-facebook-insights)[ RSS](/packages/jonasva-laravel-facebook-insights/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Facebook Insights
=========================

[](#laravel-facebook-insights)

FacebookInsights provides a quick way to access insights of a facebook page with the Facebook OpenGraph API v2. It works with a permanent access token so no user interaction is required. A common usage would be to have a statistics dashboard that needs to regularly fetch insights of a facebook page.

Installation
------------

[](#installation)

To get the latest version of FacebookInsights require it in your `composer.json` file.

```
"jonasva/laravel-facebook-insights": "dev-master"

```

*(For Laravel 4, please check the documentation of the Laravel4 branch of this repository)*

Run `composer update jonasva/laravel-facebook-insights` to install it.

Once FacebookInsights is installed you need to register its service provider with your application. Open `config/app.php` and find the `providers` key.

```
'providers' => array(

    Jonasva\FacebookInsights\FacebookInsightsServiceProvider::class,

)
```

A Facade for easy access is also included. You can register the facade in the `aliases` key of your `config/app.php` file.

```
'aliases' => array(

    'FacebookInsights' => Jonasva\FacebookInsights\Facades\FacebookInsights::class,

)
```

### Publish the configurations

[](#publish-the-configurations)

Run this on the command line from the root of your project:

```
$ php artisan vendor:publish

```

A configuration file will be published to `config/facebook-insights.php`

### Config

[](#config)

#### Facebook App and Page information

[](#facebook-app-and-page-information)

To use this package, you'll need to setup your Facebook App ID, App secret, (permanent) access token and Page ID. For more information about this check the config file.

#### Cache

[](#cache)

Facebook GraphApi responses get cache for 1 day by default. You can change this by altering the `cache-lifetime`.

Usage
-----

[](#usage)

The package contains several useful methods to fetch facebook insights with the OpenGraph API. Methods can be called by using the facade `FacebookInsights`. For example:

```
    use FacebookInsights; // this goes above your class declaration

    // ...

    $startDate = new \DateTime('2015-03-15');
    $endDate = new \DateTime('2015-03-25');
    // fetch your page's total impressions for a given period
    $totalImpressions = FacebookInsights::getPageTotalImpressions($startDate, $endDate);
```

Methods
-------

[](#methods)

This package currently provides insights for Page and Post objects. That said, any other OpenGraph queries can also be done by simply using the following method:

```
    /**
     * Construct a facebook request
     *
     * @param string $query
     * @param array $params (optional)
     * @param string $method (optional)
     * @param string $object (optional)
     *
     * @return GraphObject
     */
    public function performGraphCall($query, $params = [], $object = null, $method = 'GET')
```

### Page Insights

[](#page-insights)

Get the total amount of page fans (aka followers, people who liked the page)

```
    /**
     * Get the total amount of page fans (people who liked the page)
     *
     * @return int
     */
    public function getPageTotalFans()
```

Get new fans per day for a given period

```
    /**
     * Get new page fans per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageNewFansPerDay(\DateTime $startDate, \DateTime $endDate)
```

Get the total number of new page fans for a given period

```
    /**
     * Get the total number of new page fans for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalNewFans(\DateTime $startDate, \DateTime $endDate)
```

Get a page's impressions (The total number of impressions seen of any content associated with your Page) per day for a given period

```
    /**
     * Get the page impressions per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageImpressionsPerDay(\DateTime $startDate, \DateTime $endDate)
```

Get the total number of page impressions for a given period

```
    /**
     * Get the total number of page impressions for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalImpressions(\DateTime $startDate, \DateTime $endDate)
```

Get a page's consumptions (The number of times people clicked on any of your content) per day for a given period

```
    /**
     * Get the page consumptions per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageConsumptionsPerDay(\DateTime $startDate, \DateTime $endDate)
    {
```

Get the total number of page consumptions for a given period

```
    /**
     * Get the total number of page consumptions for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalConsumptions(\DateTime $startDate, \DateTime $endDate)
```

Get like, comment, share, rsvp, claim and answer counts for a page's posts grouped per day for a given period

```
    /**
     * Get a page's positive feedback per day for a given period
     * The following actions are categorized as positive feedback:
     * like, comment, link (share), rsvp (respond to an event), claim, answer
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPagePositiveFeedbackPerDay(\DateTime $startDate, \DateTime $endDate)
```

Get accumulated (total) like, comment, share, rsvp, claim and answer counts for a page's posts grouped per day for a given period

```
    /**
     * Get a page's accumulated positive feedback for a given period
     * The following actions are categorized as positive feedback:
     * like, comment, link (share), rsvp (respond to an event), claim, answer
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageTotalPositiveFeedback(\DateTime $startDate, \DateTime $endDate)
```

Get a specific insight for a page for a given period. Insights can be found here: [https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#page\_impressions](https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#page_impressions)

```
    /**
     * Get a specific insight for a page for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param string $insight
     * @param string $period (optional)
     *
     * @return int
     */
    public function getPageInsight(\DateTime $startDate, \DateTime $endDate, $insight, $period = 'day')
```

Get a page's posts for a given period. This is not really an insight, but is needed to get post ID's which can later be used to collect post insights.

```
    /**
     * Get the page's posts for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param int $limit
     *
     * @return array
     */
    public function getPagePosts(\DateTime $startDate, \DateTime $endDate, $limit = null)
```

### Switching to another page

[](#switching-to-another-page)

It is also possible to dynamically switch to another page, to fetch its insights / posts. You can use the `switchPage` method for that:

```
    /*
     * Switch to another page to get insights of
     *
     * @param string $pageId
     * @param string $accessToken
     */
    public function switchPage($pageId, $accessToken)
```

Example:

```
    FacebookInsights::switchPage('other page id', 'other page's permanent access token');
```

### Post Insights

[](#post-insights)

Post specific insights can only be collected by period `lifetime`, so no date range needs to be given.

Get a post's impressions

```
    /**
     * Get a post's impressions
     *
     * @param string $postId
     *
     * @return int
     */
    public function getPostImpressions($postId)
```

Get a post's consumptions

```
    /**
     * Get a post's consumptions
     *
     * @param string $postId
     *
     * @return int
     */
    public function getPostConsumptions($postId)
```

Get a specific insight for a post. Post insights can be found here: [https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#post\_impressions](https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#post_impressions)

```
    /**
     * Get a specific insight for a post
     *
     * @param string $insight
     * @param string $postId
     *
     * @return array
     */
    public function getPostInsight($postId, $insight)
```

Get the page's posts with calculated insights for a given period

```
    /**
     * Get the page's posts with calculated insights for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param int $limit
     *
     * @return array
     */
    public function getPagePostsBasicInsights(\DateTime $startDate, \DateTime $endDate, $limit = null)
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff40e2acbee6d0a3fa84877d48b332099f9cf4c4d0272d22d2b094e9aeac84de?d=identicon)[jonasva](/maintainers/jonasva)

---

Top Contributors

[![jonasva](https://avatars.githubusercontent.com/u/8156732?v=4)](https://github.com/jonasva "jonasva (14 commits)")[![ParadoxNL](https://avatars.githubusercontent.com/u/3331772?v=4)](https://github.com/ParadoxNL "ParadoxNL (4 commits)")

### Embed Badge

![Health badge](/badges/jonasva-laravel-facebook-insights/health.svg)

```
[![Health](https://phpackages.com/badges/jonasva-laravel-facebook-insights/health.svg)](https://phpackages.com/packages/jonasva-laravel-facebook-insights)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
