jlorente/laravel-appsflyer

Laravel 5.6 integration for the Jlorente Appsflyer package.

dev-master 2020-09-22 14:53 UTC

This package is auto-updated.

Last update: 2024-10-22 23:40:26 UTC


README

This extension allows you to access the Appsflyer API by a comprehensive way.

Installation

The preferred way to install this extension is through composer.

With Composer installed, you can then install the extension using the following commands:

$ php composer.phar require jlorente/laravel-appsflyer

or add

...
    "require": {
        "jlorente/laravel-appsflyer": "*"
    }

to the require section of your composer.json file.

Configuration

  1. Register the ServiceProvider in your config/app.php service provider list.

config/app.php

return [
    //other stuff
    'providers' => [
        //other stuff
        \Jlorente\Laravel\Appsflyer\AppsflyerServiceProvider::class,
    ];
];
  1. Add the following facade to the $aliases section.

config/app.php

return [
    //other stuff
    'aliases' => [
        //other stuff
        'Appsflyer' => \Jlorente\Laravel\Appsflyer\Facades\Appsflyer::class,
    ];
];
  1. Set the dev_key and api_token in the config/services.php in a new created appsflyer array.

config/services.php

return [
    //other stuff
    'appsflyer' => [
        'dev_key' => 'YOUR_DEV_KEY',
        'api_token' => 'YOUR_API_TOKEN',
        'is_active' => true,
    ];
];

Usage

You can use the facade alias Appsflyer to execute api calls. The authentication params will be automaticaly injected.

Appsflyer::inappevent()->create($data);

Notification Channel

A notification channel is included in this package and allows you to integrate the Appsflyer in app events service with the Laravel notifications.

Formatting Notifications

If a notification should trigger an Appsflyer in app event, you should define a toAppsflyer method on the notification class. This method will receive a $notifiable entity and should return a Jlorente\Laravel\Appsflyer\Notifications\Messages\AppsflyerMessage instance:

/**
 * Get the AppsflyerMessage that represents the notification.
 *
 * @param  mixed  $notifiable
 * @return \Jlorente\Laravel\Appsflyer\Notifications\Messages\AppsflyerMessage|string
 */
public function toAppsflyer($notifiable)
{
    return (new AppsflyerMessage)
                ->platform('com.mycompany.myapp')
                ->payload([
                    'eventName' => 'af_purchase'
                ]);
}

Once done, you must add the notification channel in the array of the via() method of the notification:

/**
 * Get the notification channels.
 *
 * @param  mixed  $notifiable
 * @return array|string
 */
public function via($notifiable)
{
    return [AppsflyerChannel::class];
}

You can find more info about Laravel notifications in this page.

License

Copyright © 2018 José Lorente Martín jose.lorente.martin@gmail.com.

Licensed under the BSD 3-Clause License. See LICENSE.txt for details.