Skip to content

Commit

Permalink
add google and meta sources
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Aug 31, 2024
1 parent 6d884e4 commit 99b4bb9
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ return [
|
| These are the classes containing the logic to detect the visitor's referrer.
| You can disable some of them or add as many as you want.
| Regardless of the number of sources you define, they will all be stored.
| No matter how many sources you define, they will all be stored.
|
*/
'sources' => [
Expand All @@ -59,7 +59,7 @@ return [
| These are the classes containing the logic to store the visitor's referrer.
| By default, they are all disabled. To enable a driver, add a "key" value.
| You can also add your own driver if needed.
| Regardless of the number of drivers you define, they will all store the referrer sources.
| No matter how many drivers you define, they will all store the referrer sources.
|
*/
'drivers' => [
Expand All @@ -71,6 +71,10 @@ return [
],
\Elegantly\Referrer\Drivers\CookieDriver::class => [
'key' => null,
/**
* Lifetime in seconds
*/
'lifetime' => 60 * 60 * 24 * 365,
],
],
];
Expand Down
2 changes: 2 additions & 0 deletions config/referrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
'sources' => [
\Elegantly\Referrer\Sources\UtmReferrerSource::class,
\Elegantly\Referrer\Sources\RequestHeaderSource::class,
\Elegantly\Referrer\Sources\GoogleClickIdSource::class,
\Elegantly\Referrer\Sources\MetaClickIdSource::class,
],

/*
Expand Down
56 changes: 56 additions & 0 deletions src/Sources/GoogleClickIdSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Elegantly\Referrer\Sources;

use Illuminate\Http\Request;

/**
* @see https://support.google.com/google-ads/answer/3095550
*
* @extends ReferrerSource<string|null>
*/
class GoogleClickIdSource extends ReferrerSource
{
final public function __construct(
public ?string $gclid = null,

) {
//
}

public function isEmpty(): bool
{
return blank($this->gclid);
}

public static function fromRequest(Request $request): static
{
return new static(
gclid: $request->string('gclid')->value() ?: null,
);
}

/**
* @param array{
* gclid?: string|null,
* } $values
*/
public static function fromArray(array $values): static
{
return new static(
gclid: $values['gclid'] ?? null,
);
}

/**
* @return array{
* gclid?: string|null,
* }
*/
public function toArray(): array
{
return [
'gclid' => $this->gclid,
];
}
}
56 changes: 56 additions & 0 deletions src/Sources/MetaClickIdSource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Elegantly\Referrer\Sources;

use Illuminate\Http\Request;

/**
* @see https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc/
*
* @extends ReferrerSource<string|null>
*/
class MetaClickIdSource extends ReferrerSource
{
final public function __construct(
public ?string $fbclid = null,

) {
//
}

public function isEmpty(): bool
{
return blank($this->fbclid);
}

public static function fromRequest(Request $request): static
{
return new static(
fbclid: $request->string('fbclid')->value() ?: null,
);
}

/**
* @param array{
* fbclid?: string|null,
* } $values
*/
public static function fromArray(array $values): static
{
return new static(
fbclid: $values['fbclid'] ?? null,
);
}

/**
* @return array{
* fbclid?: string|null,
* }
*/
public function toArray(): array
{
return [
'fbclid' => $this->fbclid,
];
}
}

0 comments on commit 99b4bb9

Please sign in to comment.