Christian Gallarmin
Christian Gallarmin

Reputation: 660

Spatie-laravel-analytics package ga:users not accurate

My query to fetch data from google analytics using spatie-laravel-analytics

$analyticsData = Analytics::performQuery(Period::days(30),
    'ga:',
    [
        'metrics' => 'ga:users,ga:newUsers,ga:sessions,ga:sessionsPerUser,ga:pageviews,ga:pageviewsPerSession,ga:avgSessionDuration,ga:bounceRate',
        'dimensions' => 'ga:pageTitle',
        'start-date' => '2018-08-01',
        'end-date' => '2018-08-31',
    ]);

When I tried to see what's the result inside this is what I got.

GA

And when I compare it to my google analytics 6/8 is working properlyenter image description here

Is there anyone having this kind of issue? My problem is my ga:users is not accurate from google analytics that's why my ga:sessionPerUser is giving me a incorrect value as well. Do you have any idea how to fix this? Thank you in advance.

Upvotes: 1

Views: 1088

Answers (1)

XTOTHEL
XTOTHEL

Reputation: 5208

In your laravel code, you are calling a period of days(30), while in your date range, it is actually 31 days, this might be the cause.

Use this for creating the period that you want and pass it in and remove the start-end dates from your query.

$startDate = Carbon::now()->subYear();
$endDate = Carbon::now();

Period::create($startDate, $endDate);

Upvotes: 2

Related Questions