actengage / laravel-passendo
A Passendo package for Laravel.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- laravel/framework: ^11.0
Requires (Dev)
- php: ^8.2
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^10.0
README
This is a Laravel package that makes tracking Passendo clicks easy. This package includes migrations, models, jobs, and the various handles to retry failed attempts.
composer require actengage/laravel-passendo
Basic Usage
The easiest way to use this package is to attach the trait to an Eloquent model.
You must implement a cpa()
and tid()
method to fetch the CPA's and tracking
ID's (respectively).
use Actengage\LaravelPassendo\Contracts\TrackPassendoClicks as TrackPassendoClicksInterface; use Actengage\LaravelPassendo\TrackPassendoClicks; use Illuminate\Database\Eloquent\Model; class User extends Model implements TrackPassendoClicksInterface { use Optionable, TrackPassendoClicks; public function cpa(): float { return $this->options->get('cpa'); } public function tid(): string { return $this->tracking_id; } public function shouldTrackPassendoClicks(): bool { return true; } }
Use the Click
model.
You can also create \Actengage\LaravelPassendo\Click
models just as any other
Eloquent model. Give the tracking_id
and cpa
attributes a value, and the
jobs will automatically dispatch.
use Actengage\LaravelPassendo\Click; // Manually create a click model $click = Click::create([ 'tracking_id' => 'test1', 'cpa' => 1 ]);
Polymorphic Relationships.
You may optionally associate a polymorphic relationship, which associates the click to a parent model.
$user = User::firstOrCreate([ 'email' => 'test@test.com' ]); $click->parent()->associate($user);
Using the TrackPassendoClicks
trait.
If you are implementing the \Actengage\LaravelPassendo\TrackPassendoClicks
trait, then you can use the clicks()
helper to create and associate a model
at once.
User::create()->clicks()->create([ 'tracking_id' => 'test2', 'cpa' => 1 ]);