laravel-gamp icon indicating copy to clipboard operation
laravel-gamp copied to clipboard

Although my measurement id(tid) is right, I can't hit the google analytics.

Open Sithu-Soe opened this issue 3 years ago • 8 comments

image

Sithu-Soe avatar Oct 28 '20 04:10 Sithu-Soe

Share your code!

irazasyed avatar Oct 28 '20 04:10 irazasyed

here

Route::get('/test', function(){

$analytics = new Analytics(false, false);
$uuid = (string) Str::uuid();

// Make sure AsyncRequest is set to false (it defaults to false)
$response = $analytics->setProtocolVersion('1')
                ->setTrackingId('G-DDDDDDCC')
                ->setClientId($uuid)
                ->setDebug(true)
                ->sendPageview();

$debugResponse = $response->getDebugResponse();

// The debug response is an associative array, you could use print_r to view its contents
dd($debugResponse);

});

Sithu-Soe avatar Oct 28 '20 04:10 Sithu-Soe

and using laravel gamp

$gamp = GAMP::setClientId($uuid);
$gamp->setDebug(true)->sendPageview();
dd($gamp, $debugResponse);

Sithu-Soe avatar Oct 28 '20 04:10 Sithu-Soe

Did you configure your tracking ID in config file? Please share that as well. And you do not need to initialise the Analytics class when you can just use the Facade or typehint and it'll resolve using Laravel's container.

irazasyed avatar Oct 28 '20 04:10 irazasyed

I already add my tracking id in the config file(gamp.php). Yeah, of course, I just test with both Analytics class and Gamp class from Facade. Also, I test by switching ssl (true or false ).

Sithu-Soe avatar Oct 28 '20 04:10 Sithu-Soe

my gamp config file

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Google Analytics Tracking / Web Property ID [REQUIRED]
    |--------------------------------------------------------------------------
    |
    | Your Google Analytics tracking ID / web property ID. The format is UA-XXXX-Y.
    | All collected data is associated by this ID.
    |
    | Refer:
    | https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid
    |
    */
    'tracking_id' => 'G-AAAAAAA',

    /*
    |--------------------------------------------------------------------------
    | Measurement Protocol Version [REQUIRED]
    |--------------------------------------------------------------------------
    |
    | The Protocol version. The current value is '1'.
    | This will only change when there are changes made that are not backwards compatible.
    |
    | Refer:
    | https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v
    |
    | Default: 1
    |
    */
    'protocol_version' => 1,

    /*
    |--------------------------------------------------------------------------
    | URL Endpoint - SSL Support: Send Data over SSL [Optional]
    |--------------------------------------------------------------------------
    |
    | This option controls the URL endpoint of the Measurement Protocol.
    | To send data over SSL, set true.
    |
    | Refer:
    | https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid
    |
    | Default: false
    | Valid Values: (Boolean) "true" OR "false"
    |
    */
    'is_ssl' => true,

    /*
    |--------------------------------------------------------------------------
    | Disable Hits [Optional]
    |--------------------------------------------------------------------------
    |
    | This option controls enabling or disabling the library.
    | Useful in Staging/Dev environments when you don't want to actually send hits to GA.
    | When disabled, it returns a AnalyticsResponseInterface object that returns empty values.
    |
    | To disable library hits, set true.
    |
    | Default: false
    | Valid Values: (Boolean) "true" OR "false"
    |
    */
    'is_disabled' => false,

    /*
    |--------------------------------------------------------------------------
    | Anonymize IP [Optional]
    |--------------------------------------------------------------------------
    |
    | When set to True, the IP address of the sender will be anonymized.
    |
    | Refer:
    | https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip
    |
    | Default: false
    | Valid Values: (Boolean) "true" OR "false"
    |
    */
    'anonymize_ip' => true,

    /*
    |--------------------------------------------------------------------------
    | Asynchronous Requests [Optional]
    |--------------------------------------------------------------------------
    |
    | When set to True, All the requests would be made non-blocking (Async).
    |
    | Default: false
    | Valid Values: (Boolean) "true" OR "false"
    |
    */
    'async_requests' => false,
];

Sithu-Soe avatar Oct 28 '20 04:10 Sithu-Soe

@Sithu-Soe I think it's a problem related to Web+App new analytics behavior (are you using firebase?), if you have a G-XXXX id, must use the new v2 measurement protocol, i'm struggling with the same with no results 😢. https://www.thyngster.com/app-web-google-analytics-measurement-protocol-version-2

alexlpdj avatar Nov 12 '20 14:11 alexlpdj

Follow this tutorial to set up a Universal Analytics property (UA-XXXX) instead of the Google Analytics 4 property (G-XXXX)

https://support.google.com/analytics/answer/10269537

hudhaifas avatar Dec 24 '20 05:12 hudhaifas