giftuals/affiliate-link-builder

PHP library that allows you to create affiliate links from original URLs.

v1.2.2 2024-10-17 08:31 UTC

This package is auto-updated.

Last update: 2025-06-07 14:51:04 UTC


README

PHP library that allows you to create affiliate links from original URLs.

Requirements

  • PHP >= 8.3.7

Didn't test how far you can get behind, but this definately works.

Installation

composer require giftuals/affiliate-link-builder

Supported affiliate networks

Configuration

Because merchants switch networks and there are merchants that try out multiple platforms at once, you configure each host individually.

The configuration of each host is an array that contains 2 keys:

  • 
    
  • 
    

Bol.com

Bol.com only requires you to configure:

  • 
    
$config = [
    'hosts' => [
        'bol.com' => [
            'builder_fqcn' => BolComBuilder::class,
            'network_settings' => [
                'client_specific' => [
                    'kadolijst.nl' => ['site_id' => $bol_com_nl_affiliate_id],
                    'cadeaulijst.be' => ['site_id' => $bol_com_be_affiliate_id],
                ],
            ],
        ],
    ],
];

Awin

To build affiliate links for Awin, you need:

  • 
    
  • 
    
$config = [
    'hosts' => [
        'www.dreamland.be' => [
            'builder_fqcn' => AwinBuilder::class,
            // Always use the Belgian affiliate program to create links for the Belgian website, no matter which client
            // requests it.
            'network_settings' => [
                'affiliate_id' => $awin_be_affiliate_id,
                'merchant_id' => 16159,
            ]
        ],
    ],
];

Daisycon

Daisycon requires you to configure four parameters:

  • 
    
  • 
    
  • 
    
  • 
    
$config = [
    'hosts' => [
        'www.lazylama.nl' => [
            'builder_fqcn' => DaisyconBuilder::class,
            'network_settings' => [
                'client_specific' => [
                    'kadolijst.nl' => [
                        'redirect_host' => 'jdt8.net',
                        'si' => 17366,
                        'li' => 1750503,
                        'wi' => $daisycon_nl_affiliate_id,
                    ],
                ],
            ],
        ],
    ],
];

TradeTracker

TradeTracker links require the following:

  • 
    
$config = [
    'hosts' => [
        'www.babykadowinkel.nl' => [
            'builder_fqcn' => TradeTrackerBuilder::class,
            'network_settings' => [
                'affiliate_url_pattern' => 'https://www.babykadowinkel.nl/website/Includes/TradeTracker/?tt=<programID>_12_<affiliateID>_&r=%s',
            ],
        ],
    ],
];

Example usage

$config = [
    'hosts' => [
        'bol.com' => [
            'builder_fqcn' => 'Giftuals\AffiliateLinkBuilder\Builders\BolComBuilder',
            'network_settings' => [
                'site_id' => 123,
            ],
        ],
    ],
];
$builder = new Giftuals\AffiliateLinkBuilder\AffiliateLinkBuilder($config);
$url = 'https://www.bol.com/nl/nl/p/furreal-friends-cubby-interactive-plush-curious-bear/9200000113960520';
$affiliate_link = $builder->getAffiliateLink($url);

Authors

Coen Coppens (giftuals)

License

Licensed under the MIT License