components
2 days ago
hooks
2 days ago
License.jsx
2 days ago
addon-catalog.js
2 days ago
route.jsx
2 days ago
utils.js
2 days ago
addon-catalog.js
183 lines
| 1 | /** |
| 2 | * WordPress Dependencies |
| 3 | */ |
| 4 | import { __ } from '@wordpress/i18n'; |
| 5 | |
| 6 | /** |
| 7 | * Display metadata for license add-on ids (matches PHP ADDON_PLUGIN_FILES keys). |
| 8 | * |
| 9 | * @type {Record<string, { title: string, description: string, learnMore: string, manualUrl: string, iconId: string }>} |
| 10 | */ |
| 11 | export const LICENSE_ADDON_CATALOG = { |
| 12 | pro: { |
| 13 | title: __( 'Advanced Ads Pro', 'advanced-ads' ), |
| 14 | description: __( |
| 15 | 'Take the monetization of your website to the next level.', |
| 16 | 'advanced-ads' |
| 17 | ), |
| 18 | learnMore: |
| 19 | 'https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=advancedads&utm_medium=in-plugin&utm_campaign=a2-in_plugin-licenses_addons-pro_addon_learn_more', |
| 20 | manualUrl: |
| 21 | 'https://wpadvancedads.com/manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 22 | iconId: 'pro', |
| 23 | }, |
| 24 | responsive: { |
| 25 | title: __( 'AMP Ads', 'advanced-ads' ), |
| 26 | description: __( |
| 27 | 'Integrate your ads on AMP (Accelerated Mobile Pages) and auto-convert your Google AdSense ad units for enhanced mobile performance.', |
| 28 | 'advanced-ads' |
| 29 | ), |
| 30 | learnMore: |
| 31 | 'https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 32 | manualUrl: |
| 33 | 'https://wpadvancedads.com/manual/ads-on-amp-pages/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 34 | iconId: 'ampads', |
| 35 | }, |
| 36 | gam: { |
| 37 | title: __( 'Google Ad Manager Integration', 'advanced-ads' ), |
| 38 | description: __( |
| 39 | 'Simplify the process of implementing ad units from Google Ad Manager swiftly and without errors.', |
| 40 | 'advanced-ads' |
| 41 | ), |
| 42 | learnMore: |
| 43 | 'https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 44 | manualUrl: |
| 45 | 'https://wpadvancedads.com/manual/google-ad-manager-integration-manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 46 | iconId: 'gam', |
| 47 | }, |
| 48 | layer: { |
| 49 | title: __( 'PopUp and Layer Ads', 'advanced-ads' ), |
| 50 | description: __( |
| 51 | 'Capture attention with customizable pop-ups that ensure your ads and messages get noticed.', |
| 52 | 'advanced-ads' |
| 53 | ), |
| 54 | learnMore: |
| 55 | 'https://wpadvancedads.com/add-ons/popup-and-layer-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 56 | manualUrl: |
| 57 | 'https://wpadvancedads.com/manual/popup-and-layer-ads-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 58 | iconId: 'popuplayer', |
| 59 | }, |
| 60 | selling: { |
| 61 | title: __( 'Selling Ads', 'advanced-ads' ), |
| 62 | description: __( |
| 63 | "Earn more money by enabling advertisers to buy ad space directly on your site's frontend.", |
| 64 | 'advanced-ads' |
| 65 | ), |
| 66 | learnMore: |
| 67 | 'https://wpadvancedads.com/add-ons/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 68 | manualUrl: |
| 69 | 'https://wpadvancedads.com/manual/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 70 | iconId: 'sellingads', |
| 71 | }, |
| 72 | sticky: { |
| 73 | title: __( 'Sticky Ads', 'advanced-ads' ), |
| 74 | description: __( |
| 75 | 'Increase click rates by anchoring ads in sticky positions above, alongside, or below your website.', |
| 76 | 'advanced-ads' |
| 77 | ), |
| 78 | learnMore: |
| 79 | 'https://wpadvancedads.com/add-ons/sticky-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 80 | manualUrl: |
| 81 | 'https://wpadvancedads.com/manual/sticky-ads-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 82 | iconId: 'stickyads', |
| 83 | }, |
| 84 | tracking: { |
| 85 | title: __( 'Tracking', 'advanced-ads' ), |
| 86 | description: __( |
| 87 | 'Monitor your ad performance to maximize your revenue.', |
| 88 | 'advanced-ads' |
| 89 | ), |
| 90 | learnMore: |
| 91 | 'https://wpadvancedads.com/add-ons/tracking/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 92 | manualUrl: |
| 93 | 'https://wpadvancedads.com/manual/tracking-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 94 | iconId: 'tracking', |
| 95 | }, |
| 96 | }; |
| 97 | |
| 98 | /** Manual installation guide (zip upload via Plugins screen). */ |
| 99 | export const MANUAL_INSTALL_GUIDE_URL = |
| 100 | 'https://wpadvancedads.com/manual/how-to-install-an-add-on/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-manual-install'; |
| 101 | |
| 102 | /** |
| 103 | * @param {string} [addonId] Short add-on id for campaign tracking. |
| 104 | * @return {string} Manual install documentation URL. |
| 105 | */ |
| 106 | export function getManualInstallGuideUrl( addonId = '' ) { |
| 107 | if ( ! addonId ) { |
| 108 | return MANUAL_INSTALL_GUIDE_URL; |
| 109 | } |
| 110 | |
| 111 | const url = new URL( MANUAL_INSTALL_GUIDE_URL ); |
| 112 | url.searchParams.set( 'addon', addonId ); |
| 113 | return url.toString(); |
| 114 | } |
| 115 | |
| 116 | /** @type {string[]} Default All Access add-on ids when shop omits addons[]. */ |
| 117 | export const ALL_ACCESS_ADDON_IDS = [ |
| 118 | 'pro', |
| 119 | 'responsive', |
| 120 | 'gam', |
| 121 | 'layer', |
| 122 | 'selling', |
| 123 | 'sticky', |
| 124 | 'tracking', |
| 125 | ]; |
| 126 | |
| 127 | /** |
| 128 | * @param {string} addonId License add-on id. |
| 129 | * @return {string} Icon URL under plugin assets. |
| 130 | */ |
| 131 | export function getAddonIconUrl( addonId ) { |
| 132 | const catalog = LICENSE_ADDON_CATALOG[ addonId ]; |
| 133 | const iconId = catalog?.iconId ?? addonId; |
| 134 | const base = advancedAds?.endpoints?.assetsUrl ?? ''; |
| 135 | |
| 136 | return `${ base }assets/img/add-ons/aa-addons-icons-${ iconId }.svg`; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Build list rows for the Included add-ons UI. |
| 141 | * |
| 142 | * @param {Object} license Rich license row. |
| 143 | * @return {Array<object>} Array of formatted add-on rows for rendering in the UI. |
| 144 | */ |
| 145 | export function getIncludedAddonsForLicense( license ) { |
| 146 | const bundleUrl = String( license?.download_url ?? '' ); |
| 147 | const fromApi = Array.isArray( license?.addons ) ? license.addons : []; |
| 148 | |
| 149 | const entries = |
| 150 | fromApi.length > 0 |
| 151 | ? fromApi |
| 152 | .map( ( row ) => ( { |
| 153 | id: String( row?.name ?? '' ).trim(), |
| 154 | downloadUrl: String( row?.download_url ?? '' ).trim(), |
| 155 | } ) ) |
| 156 | .filter( ( row ) => row.id ) |
| 157 | : ALL_ACCESS_ADDON_IDS.map( ( id ) => ( { |
| 158 | id, |
| 159 | downloadUrl: bundleUrl, |
| 160 | } ) ); |
| 161 | |
| 162 | return entries.map( ( { id, downloadUrl } ) => { |
| 163 | const meta = LICENSE_ADDON_CATALOG[ id ] ?? { |
| 164 | title: id, |
| 165 | description: '', |
| 166 | learnMore: |
| 167 | 'https://wpadvancedads.com/add-ons/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons', |
| 168 | manualUrl: |
| 169 | 'https://wpadvancedads.com/manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=licenses-add-ons-manual', |
| 170 | }; |
| 171 | |
| 172 | return { |
| 173 | id, |
| 174 | title: meta.title, |
| 175 | description: meta.description, |
| 176 | learnMore: meta.learnMore, |
| 177 | manualUrl: meta.manualUrl, |
| 178 | icon: getAddonIconUrl( id ), |
| 179 | downloadUrl, |
| 180 | }; |
| 181 | } ); |
| 182 | } |
| 183 |