aawnu / php-ga4

PHP Wrapper for Google Analytics 4 with Server Side Tracking

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rationale for Analytics::new()

8ctopus opened this issue · comments

Hi again Alex,

What is the rationale for Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true) instead of new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)?

Hi again Alex,

What is the rationale for Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true) instead of new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)?

Thats mainly a readability thing for quick nested methods

$analytics = new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true);
$analytics->method()
    ->method()
    ->method();

compared to

$analytics = (new Analytics('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true))
    ->method()
    ->method()
    ->method();

compared to

$analytics = Analytics::new('G-XXXXXX', 'eMVPMEcTbaI1iuWtrPw', true)
    ->method()
    ->method()
    ->method();

Oh I see, thank you for the explanation, I mainly use the second option, now I know one more.