-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added ShortUrlTracing Model/Migration/Factory. - Added withTracing() option to UrlService builder - Added ability to filter clicks based on UTM parameters. - Added eager loading relationships when using FindBy methods on UrlService. - Updated Test Coverage. - Updated Readme with UTM Support Information.
- Loading branch information
Showing
28 changed files
with
1,161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace YorCreative\UrlShortener\Builders\UrlBuilder\Options; | ||
|
||
use Illuminate\Support\Collection; | ||
use YorCreative\UrlShortener\Builders\UrlBuilder\UrlBuilderOptionInterface; | ||
use YorCreative\UrlShortener\Exceptions\TracingRepositoryException; | ||
use YorCreative\UrlShortener\Exceptions\UrlRepositoryException; | ||
use YorCreative\UrlShortener\Repositories\TracingRepository; | ||
use YorCreative\UrlShortener\Repositories\UrlRepository; | ||
|
||
class WithTracing implements UrlBuilderOptionInterface | ||
{ | ||
/** | ||
* @param Collection $shortUrlCollection | ||
* | ||
* @throws UrlRepositoryException | ||
* @throws TracingRepositoryException | ||
*/ | ||
public function resolve(Collection &$shortUrlCollection): void | ||
{ | ||
$sanitizedUtmParameters = TracingRepository::sanitizeUtmArray( | ||
$shortUrlCollection->get('utm_parameters') | ||
); | ||
|
||
$trace = [ | ||
'short_url_id' => UrlRepository::findByIdentifier( | ||
$shortUrlCollection->get('identifier') | ||
)->id, | ||
]; | ||
|
||
$trace = array_merge($trace, $sanitizedUtmParameters); | ||
|
||
TracingRepository::create($trace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace YorCreative\UrlShortener\Exceptions; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
class TracingRepositoryException extends Exception | ||
{ | ||
public function __construct($message = '', $code = 0, Throwable $previous = null) | ||
{ | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace YorCreative\UrlShortener\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use YorCreative\UrlShortener\Traits\PublishableHasFactory; | ||
|
||
class ShortUrlTracing extends Model | ||
{ | ||
use PublishableHasFactory; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $incrementing = true; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $table = 'short_url_tracings'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'id'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $fillable = [ | ||
'short_url_id', | ||
'utm_id', | ||
'utm_source', | ||
'utm_medium', | ||
'utm_campaign', | ||
'utm_content', | ||
'utm_term', | ||
]; | ||
|
||
protected $hidden = [ | ||
'deleted_at', | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
/** | ||
* @return BelongsTo | ||
*/ | ||
public function shortUrl(): BelongsTo | ||
{ | ||
return $this->belongsTo(ShortUrl::class, 'short_url_id', 'id'); | ||
} | ||
} |
Oops, something went wrong.