Skip to content

Commit

Permalink
add tiktok
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Oct 1, 2024
1 parent 1131dd8 commit 59ecdb3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
27 changes: 14 additions & 13 deletions config/referrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
\Elegantly\Referrer\Sources\RequestHeaderSource::class,
\Elegantly\Referrer\Sources\GoogleClickIdSource::class,
\Elegantly\Referrer\Sources\MetaClickIdSource::class,
\Elegantly\Referrer\Sources\TikTokClickIdSource::class,
],

/*
Expand All @@ -30,18 +31,18 @@
|
*/
'drivers' => [
\Elegantly\Referrer\Drivers\ContextDriver::class => [
'key' => null,
],
\Elegantly\Referrer\Drivers\SessionDriver::class => [
'key' => null,
],
\Elegantly\Referrer\Drivers\CookieDriver::class => [
'key' => null,
/**
* Lifetime in seconds
*/
'lifetime' => 60 * 60 * 24 * 365,
],
// \Elegantly\Referrer\Drivers\ContextDriver::class => [
// 'key' => 'referrer',
// ],
// \Elegantly\Referrer\Drivers\SessionDriver::class => [
// 'key' => 'referrer',
// ],
// \Elegantly\Referrer\Drivers\CookieDriver::class => [
// 'key' => Str::slug(env('APP_NAME', 'laravel'), '_').'referrer',
// /**
// * Lifetime in seconds
// */
// 'lifetime' => 60 * 60 * 24 * 365,
// ],
],
];
56 changes: 56 additions & 0 deletions src/Sources/TikTokClickIdSource.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://business-api.tiktok.com/portal/docs?id=1771100879787009
*
* @extends ReferrerSource<string|null>
*/
class TikTokClickIdSource extends ReferrerSource
{
final public function __construct(
public ?string $ttclid = null,

) {
//
}

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

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

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

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

0 comments on commit 59ecdb3

Please sign in to comment.