### Install WeCanTrack API Package Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Use Composer to install the required library. ```shell $ composer require wecantrack/api ``` -------------------------------- ### Retrieve Websites Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Fetch all registered websites or find a specific one by ID. ```php use WeCanTrack\API\Websites $websites = (new Websites(API_KEY))->get(); foreach($websites as $data) { echo $data['id']; echo $data['url']; echo $data['active']; } // get single website data by id $data = $websites->findById(123); echo $data['id']; echo $data['url']; echo $data['active']; ``` -------------------------------- ### Handle API Errors and Debugging Source: https://context7.com/vzangloo/wecantrack/llms.txt Demonstrates enabling debug mode and handling errors for ClickOut and Transaction API requests. ```php debug(true) // Enable debug mode ->affiliateUrl('https://affiliate.com/link') ->clickoutUrl('https://your-site.com/click') ->get(); // Check validity before accessing data if ($clickOut->isValid()) { $url = $clickOut->getAffiliateUrl(); } else { // Access all errors $errors = $clickOut->getErrors(); foreach ($errors as $error) { error_log("ClickOut Error: " . $error); } } // Alternative error check if ($clickOut->hasError()) { echo "Request failed with " . count($clickOut->getErrors()) . " errors"; } // Transactions with invalid status handling $transactions = (new Transactions('your-api-key')) ->status(['invalid_status']) // Will add error ->get('2024-01-01', '2024-01-31'); // Response iteration stops on error foreach ($transactions as $row) { // Loop exits if hasError() returns true echo $row['transaction_id']; } if ($transactions->hasError()) { print_r($transactions->getErrors()); } ``` -------------------------------- ### Manage Websites via Websites API Source: https://context7.com/vzangloo/wecantrack/llms.txt Retrieves registered websites and allows lookup by ID. Includes validation checks for request success. ```php get(); // Iterate through all websites foreach ($websites as $site) { echo "Website ID: " . $site['id']; echo "URL: " . $site['url']; echo "Active: " . ($site['active'] ? 'Yes' : 'No'); } // Find specific website by ID $website = $websites->findById(123); if (!empty($website)) { echo "Found Website: " . $website['url']; echo "Status: " . ($website['active'] ? 'Active' : 'Inactive'); } echo "Total Websites: " . $websites->getCount(); // Validation check if ($websites->isValid()) { echo "Request successful"; } else { print_r($websites->getErrors()); } ``` -------------------------------- ### Retrieve Affiliate Networks via Networks API Source: https://context7.com/vzangloo/wecantrack/llms.txt Fetches all supported affiliate networks and iterates through their metadata. Requires a valid API key. ```php get(); // Iterate through available networks foreach ($networks as $network) { echo "Network ID: " . $network['id']; echo "Network Name: " . $network['name']; // Additional network properties as available } echo "Total Networks: " . $networks->getCount(); // Error handling if ($networks->hasError()) { foreach ($networks->getErrors() as $error) { echo "Error: " . $error; } } ``` -------------------------------- ### Retrieve Websites Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Fetches all websites registered in the WeCanTrack account. ```APIDOC ## GET /websites ### Description Retrieves a list of all websites linked to the account. ### Response #### Success Response (200) - **id** (int) - Website ID. - **url** (string) - Website URL. - **active** (boolean) - Whether the website is currently active. ``` -------------------------------- ### Generate Tracked Click-Out URL with PHP Source: https://context7.com/vzangloo/wecantrack/llms.txt Use the ClickOut class to generate a tracked affiliate URL. Provide your API key and original affiliate URL. You can optionally set IP address, metadata, custom indices, redirect URL, and a click reference. ```php affiliateUrl('https://www.awin1.com/cread.php?awinmid=10921&awinaffid=211395&clickref2=MY') ->clickoutUrl('https://your-site.com/clickout') ->ipAddress('192.168.1.1') ->metadata([ 'campaign_id' => 'summer_2024', 'source' => 'homepage_banner', 'custom_1' => 'additional_data' ]) ->customIndex('product_category', 1) ->customIndex('user_segment', 2) ->redirectUrl('https://your-site.com/redirect-landing') ->useClickReference('user_ref_12345') ->get(); // Check response and extract tracking data if ($clickOut->isValid()) { // Get the tracked affiliate URL to redirect users $trackedUrl = $clickOut->getAffiliateUrl(); echo "Redirect user to: " . $trackedUrl; // Extract WeCanTrack reference for conversion attribution // Format: wct{timestamp}{random} e.g., wct200514135314e7x4d $reference = $clickOut->getReference(); echo "WCT Reference: " . $reference; } else { // Handle errors $errors = $clickOut->getErrors(); foreach ($errors as $error) { echo "Error: " . $error; } } ``` -------------------------------- ### Utilities Helper Source: https://context7.com/vzangloo/wecantrack/llms.txt Provides helper methods for extracting WeCanTrack references from URLs or text strings. ```APIDOC ## Utilities Helper ### Description Provides helper methods for extracting WeCanTrack references from URLs or text strings, useful for parsing tracking data from affiliate URLs or log files. ### Method Static Method ### Endpoint N/A (Helper Class) ### Parameters #### Static Method Parameters - **extractReference(string $input)** - Required - The URL or text string to extract the reference from. ### Request Example ```php get(); foreach($accounts as $account) { echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled']; ...... } echo $accounts->getCount(); // return Accounts count // get single account data by id $account = $accounts->findById(123); echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled']; ``` -------------------------------- ### Generate ClickOut URL Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Create a tracked click-out URL with metadata and validate the response. ```php use WeCanTrack\API\ClickOut; $clickOut = (new ClickOut(API_KEY)) ->affiliateUrl('https://www.awin1.com/cread.php?awinmid=10921&awinaffid=211395&clickref2=MY&...') ->clickoutUrl('https://your-clickout-url.com/clickout') ->ipAddress('your-ip-address') ->metadata([ 'custom_1' => 'custom_data', 'custom_2' => 'custom_data2', ]) ->get(); if($clickOut->isValid()) { echo $clickOut->getAffiliateUrl(); echo $clickOut->getReference(); // return WCT reference. Example: wct200514135314e7x4d } else { var_dump($clickOut->getErrors()); } ``` -------------------------------- ### Extract Tracking References with Utilities Helper Source: https://context7.com/vzangloo/wecantrack/llms.txt Parses WeCanTrack references from URLs or text strings. Returns null if no valid reference is found. ```php get(); // Iterate through all accounts foreach ($accounts as $account) { echo "Account ID: " . $account['id']; echo "Account Name: " . $account['name']; echo "Network ID: " . $account['network_id']; echo "Is Enabled: " . ($account['is_enabled'] ? 'Yes' : 'No'); echo "Created At: " . $account['created_at']; } echo "Total Accounts: " . $accounts->getCount(); // Filter by specific account IDs $filteredAccounts = (new NetworkAccounts('your-api-key')) ->ids(12) // Single ID ->get(); $multipleAccounts = (new NetworkAccounts('your-api-key')) ->ids([12, 123, 1234]) // Multiple IDs ->get(); // Find specific account by ID $account = $accounts->findById(123); if (!empty($account)) { echo "Found Account: " . $account['name']; echo "Network: " . $account['network_id']; } // Get earliest account creation date $earliestDate = $accounts->getEarliestCreatedDate('Y-m-d'); echo "First account created: " . $earliestDate; // Custom date format $formattedDate = $accounts->getEarliestCreatedDate('F j, Y'); echo "First account: " . $formattedDate; // e.g., "January 15, 2023" ``` -------------------------------- ### Retrieve and Filter Transactions Source: https://context7.com/vzangloo/wecantrack/llms.txt Use the Transactions class to fetch affiliate conversion data with support for date ranges, status filters, and automatic pagination. ```php get($startDate, $endDate, Transactions::LAST_WCT_UPDATE); // Available date types: // Transactions::ORDER_DATE - Filter by order/purchase date // Transactions::MODIFIED_DATE - Filter by last modification date // Transactions::CLICK_DATE - Filter by click date // Transactions::VALIDATION_DATE - Filter by validation date // Transactions::LAST_WCT_UPDATE - Filter by last WCT update (default) // Iterate through all transactions (auto-pagination) foreach ($records as $row) { echo "Transaction ID: " . $row['transaction_id']; echo "Reference: " . $row['reference']; // wct200514135314e7x4d echo "Order Date: " . $row['order_date']; echo "Status: " . $row['status']; // pending, approved, declined echo "Sale Amount: " . $row['sale_amount']; echo "Commission: " . $row['commission_amount']; echo "Metadata: " . print_r($row['click_metadata'], true); } echo "Total Transactions: " . $records->getTotalCount(); // Advanced filtering with status and network account $filteredRecords = (new Transactions('your-api-key')) ->networkAccountId(123) ->networkId('awin') ->networkAccountTags(['premium', 'eu_region']) ->status([ Transactions::STATUS_PENDING, Transactions::STATUS_APPROVED, // Transactions::STATUS_DECLINED ]) ->get($startDate, $endDate, Transactions::ORDER_DATE); // Pagination control for large datasets $paginatedRecords = (new Transactions('your-api-key')) ->status([Transactions::STATUS_APPROVED]) ->limit(500) // Max 1000 per request ->get($startDate, $endDate); // Process specific page only foreach ($paginatedRecords->limit(100)->page(3) as $row) { echo $row['transaction_id']; } // Access pagination metadata echo "Current Page: " . $paginatedRecords->getCurrentPage(); echo "Total Pages: " . $paginatedRecords->getTotalPages(); echo "Last Page: " . $paginatedRecords->getLastPage(); echo "Per Page: " . $paginatedRecords->getPerPage(); echo "Page Count: " . $paginatedRecords->getCount(); echo "Next URL: " . $paginatedRecords->getNextUrl(); echo "Previous URL: " . $paginatedRecords->getPreviousUrl(); ``` -------------------------------- ### ClickOut URL Generation Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Generates a tracked affiliate URL using the ClickOut service. ```APIDOC ## ClickOut URL Generation ### Description Creates a tracked affiliate URL by providing the original affiliate URL, clickout destination, IP address, and optional metadata. ### Parameters #### Request Body - **affiliateUrl** (string) - Required - The original affiliate tracking URL. - **clickoutUrl** (string) - Required - The destination URL for the clickout. - **ipAddress** (string) - Required - The user's IP address. - **metadata** (array) - Optional - Custom key-value pairs for tracking data. ### Response #### Success Response (200) - **isValid** (boolean) - Indicates if the request was successful. - **getAffiliateUrl** (string) - The processed affiliate URL. - **getReference** (string) - The unique WCT reference ID. ``` -------------------------------- ### Extract Reference using Utilities Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Use the extractReference method to retrieve a tracking reference from a given URL string. ```phpt use WeCanTrack\Helper\Utilities; echo Utilities::extractReference($url); // return wct200514135314e7x4d ``` -------------------------------- ### Websites API Source: https://context7.com/vzangloo/wecantrack/llms.txt Retrieves information about websites registered in the WeCanTrack platform, allowing publishers to monitor their tracked properties and their active status. ```APIDOC ## Websites API ### Description Retrieves information about websites registered in the WeCanTrack platform, allowing publishers to monitor their tracked properties and their active status. ### Method GET ### Endpoint /websites ### Parameters #### Query Parameters - **api_key** (string) - Required - Your WeCanTrack API key. ### Request Example ```php get(); foreach ($websites as $site) { echo "Website ID: " . $site['id']; echo "URL: " . $site['url']; echo "Active: " . ($site['active'] ? 'Yes' : 'No'); } $website = $websites->findById(123); if (!empty($website)) { echo "Found Website: " . $website['url']; echo "Status: " . ($website['active'] ? 'Active' : 'Inactive'); } echo "Total Websites: " . $websites->getCount(); if ($websites->isValid()) { echo "Request successful"; } else { print_r($websites->getErrors()); } ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the website. - **url** (string) - The URL of the website. - **active** (boolean) - Indicates if the website is currently active. #### Response Example ```json [ { "id": 1, "url": "https://example.com", "active": true }, { "id": 2, "url": "https://anothersite.org", "active": false } ] ``` ``` -------------------------------- ### Paginate Transaction Results Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Retrieve a specific page of transaction records with a defined limit. ```php use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->status([ Transactions::STATUS_PENDING, ]) ->get($startDate, $endDate); // return max 600 rows from page 3 only. foreach($records->limit(600)->page(3) as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count. echo $records->getCount(); // get the rows count for current page. ``` -------------------------------- ### Retrieve Network Accounts Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Fetches all network accounts associated with the API key, with optional filtering by ID. ```APIDOC ## GET /network-accounts ### Description Retrieves a list of all network accounts. Supports filtering by specific account IDs. ### Parameters #### Query Parameters - **ids** (int|array) - Optional - Filter results by one or more account IDs. ### Response #### Success Response (200) - **id** (int) - Account ID. - **name** (string) - Account name. - **network_id** (int) - Associated network ID. - **is_enabled** (boolean) - Status of the account. ``` -------------------------------- ### Filter Network Accounts by ID Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Retrieve specific network accounts by providing one or multiple IDs. ```php use WeCanTrack\API\{Networks, NetworkAccounts}; $networkAccounts = new NetworkAccounts(API_KEY); $accounts = $networkAccounts->ids(12)->get(); // get account where its id = 12 // or $accounts = $networkAccounts->ids([12, 123, 1234])->get(); // get accounts where its ids are 12, 123, 1234 foreach($accounts as $account) { echo $account['id']; echo $account['name']; echo $account['network_id']; echo $account['is_enabled']; ...... } echo $accounts->getCount(); // return Accounts count ``` -------------------------------- ### Retrieve Transactions Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Fetch transaction records within a specific date range. ```php use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY))->get($startDate, $endDate); foreach($records as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d echo $row['order_date']; echo $row['validation_date']; echo $row['status']; echo $row['sale_amount']; echo $row['commission_amount']; var_dump($row['click_metadata']); ...... } echo $records->getTotalCount(); // get all record count. ``` -------------------------------- ### Limit Transaction Results Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Apply a limit to the number of transaction records returned. ```php use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->status([ Transactions::STATUS_PENDING, ]) ->get($startDate, $endDate); // every page request return max 500 rows only foreach($records->limit(500) as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count. ``` -------------------------------- ### Error Handling and Debug Mode Source: https://context7.com/vzangloo/wecantrack/llms.txt Details on error handling capabilities and enabling debug mode for API requests. ```APIDOC ## Error Handling and Debug Mode ### Description All API classes and responses include built-in error handling capabilities through the Error trait, supporting validation checks, error collection, and optional debug mode for development. ### Method Various API methods (e.g., `get()`, `post()`, etc.) and configuration methods (`debug()`). ### Endpoint N/A (Applies to all API endpoints) ### Parameters #### Debug Mode - **debug(bool $enable)** - Optional - Enables or disables debug mode. When enabled, more detailed logs and error information may be returned. ### Request Example ```php debug(true) // Enable debug mode ->affiliateUrl('https://affiliate.com/link') ->clickoutUrl('https://your-site.com/click') ->get(); // Check validity before accessing data if ($clickOut->isValid()) { $url = $clickOut->getAffiliateUrl(); } else { // Access all errors $errors = $clickOut->getErrors(); foreach ($errors as $error) { error_log("ClickOut Error: " . $error); } } // Alternative error check if ($clickOut->hasError()) { echo "Request failed with " . count($clickOut->getErrors()) . " errors"; } // Example with invalid status use WeCanTrack\API\Transactions; $transactions = (new Transactions('your-api-key')) ->status(['invalid_status']) ->get('2024-01-01', '2024-01-31'); foreach ($transactions as $row) { echo $row['transaction_id']; } if ($transactions->hasError()) { print_r($transactions->getErrors()); } ``` ### Response #### Error Response - **errors** (array) - An array of error messages encountered during the request. #### Response Example (Error) ```json { "errors": [ "Invalid status provided: invalid_status", "API key is missing or invalid." ] } ``` ``` -------------------------------- ### Network Accounts API Source: https://context7.com/vzangloo/wecantrack/llms.txt Retrieves information about connected affiliate network accounts with filtering capabilities. ```APIDOC ## Network Accounts API ### Description The NetworkAccounts class retrieves information about connected affiliate network accounts, supporting filtering by specific account IDs and providing methods to find accounts by ID. ### Parameters #### Query Parameters - **ids** (int|array) - Optional - Filter by single or multiple account IDs ### Response #### Success Response (200) - **id** (int) - Account ID - **name** (string) - Account name - **network_id** (string) - Network identifier - **is_enabled** (boolean) - Status of the account - **created_at** (string) - Creation timestamp ``` -------------------------------- ### Retrieve Transactions Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Fetches transaction records within a date range, supporting status filtering, pagination, and limits. ```APIDOC ## GET /transactions ### Description Retrieves transaction data for a specified date range. Supports filtering by network account and status, as well as pagination. ### Parameters #### Query Parameters - **startDate** (string) - Required - Start date (YYYY-MM-DD). - **endDate** (string) - Required - End date (YYYY-MM-DD). - **networkAccountId** (int) - Optional - Filter by specific network account. - **status** (array) - Optional - Filter by transaction status (e.g., PENDING, APPROVED). - **limit** (int) - Optional - Max records per page. - **page** (int) - Optional - Page number for pagination. ### Response #### Success Response (200) - **transaction_id** (string) - Unique transaction ID. - **reference** (string) - WCT reference string. - **order_date** (string) - Date of the order. - **status** (string) - Current status of the transaction. - **sale_amount** (float) - Total sale amount. - **commission_amount** (float) - Earned commission. ``` -------------------------------- ### Transactions API Source: https://context7.com/vzangloo/wecantrack/llms.txt Retrieves affiliate conversion data with support for date ranges, status filtering, network account filtering, and pagination. ```APIDOC ## Transactions API ### Description The Transactions class retrieves affiliate conversion data with comprehensive filtering options including date ranges, network accounts, status filters, and pagination. ### Parameters #### Query Parameters - **startDate** (string) - Required - Start date for the range (YYYY-MM-DD) - **endDate** (string) - Required - End date for the range (YYYY-MM-DD) - **dateType** (constant) - Optional - Type of date to filter by (ORDER_DATE, MODIFIED_DATE, CLICK_DATE, VALIDATION_DATE, LAST_WCT_UPDATE) - **networkAccountId** (int) - Optional - Filter by specific network account ID - **networkId** (string) - Optional - Filter by network identifier - **networkAccountTags** (array) - Optional - Filter by account tags - **status** (array) - Optional - Filter by transaction status (pending, approved, declined) - **limit** (int) - Optional - Number of records per page (max 1000) - **page** (int) - Optional - Page number for pagination ### Response #### Success Response (200) - **transaction_id** (string) - Unique identifier - **reference** (string) - Transaction reference - **order_date** (string) - Date of the order - **status** (string) - Current status - **sale_amount** (float) - Total sale amount - **commission_amount** (float) - Earned commission - **click_metadata** (array) - Associated metadata ``` -------------------------------- ### Networks API Source: https://context7.com/vzangloo/wecantrack/llms.txt Retrieves the list of all available affiliate networks supported by WeCanTrack, providing network identifiers and metadata for integration purposes. ```APIDOC ## Networks API ### Description Retrieves the list of all available affiliate networks supported by WeCanTrack, providing network identifiers and metadata for integration purposes. ### Method GET ### Endpoint /networks ### Parameters #### Query Parameters - **api_key** (string) - Required - Your WeCanTrack API key. ### Request Example ```php get(); foreach ($networks as $network) { echo "Network ID: " . $network['id']; echo "Network Name: " . $network['name']; } echo "Total Networks: " . $networks->getCount(); if ($networks->hasError()) { foreach ($networks->getErrors() as $error) { echo "Error: " . $error; } } ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the network. - **name** (string) - The name of the affiliate network. #### Response Example ```json [ { "id": 1, "name": "Example Network 1" }, { "id": 2, "name": "Example Network 2" } ] ``` ``` -------------------------------- ### Filter Transactions Source: https://github.com/vzangloo/wecantrack/blob/master/README.md Retrieve transactions filtered by network account ID and status. ```php use WeCanTrack\API\Transactions; $startDate = '2019-01-01'; $endDate = '2019-01-31'; $records = (new Transactions(API_KEY)) ->networkAccountId(123) ->status([ Transactions::STATUS_PENDING, Transactions::STATUS_APPROVED, ]) ->get($startDate, $endDate, Transactions::LAST_WCT_UPDATE); foreach($records as $row) { echo $row['transaction_id']; echo $row['reference']; // return wct200514135314e7x4d ...... } echo $records->getTotalCount(); // get all record count. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.