$device, 'browser' => $browser, 'os' => $os, ); } /** * Detect affiliate platform from URL * * @param string $url The affiliate URL. * @return string Platform identifier. */ public static function detect_platform( string $url ): string { if ( strpos( $url, 'amazon.' ) !== false ) { return 'amazon'; } if ( strpos( $url, 'ebay.' ) !== false ) { return 'ebay'; } if ( strpos( $url, 'aliexpress.' ) !== false ) { return 'aliexpress'; } return 'other'; } /** * Get HTML tracking attributes for an affiliate link * * @param string $url The affiliate URL. * @param string $block_type Block type identifier. * @param string $element_type Element type identifier. * @return string HTML attribute string. */ public static function get_tracking_attributes( string $url, string $block_type, string $element_type ): string { $platform = self::detect_platform( $url ); return sprintf( 'data-affx-track="1" data-affx-block="%s" data-affx-element="%s" data-affx-platform="%s"', esc_attr( $block_type ), esc_attr( $element_type ), esc_attr( $platform ) ); } }