Changeset 3296257
- Timestamp:
- 05/19/2025 08:02:33 AM (10 months ago)
- Location:
- metrion
- Files:
-
- 27 added
- 7 edited
-
tags/1.3.0 (added)
-
tags/1.3.0/assets (added)
-
tags/1.3.0/assets/icon-128x128.png (added)
-
tags/1.3.0/assets/icon-256x256.png (added)
-
tags/1.3.0/core.php (added)
-
tags/1.3.0/css (added)
-
tags/1.3.0/css/settings.css (added)
-
tags/1.3.0/includes (added)
-
tags/1.3.0/includes/event_capture.php (added)
-
tags/1.3.0/includes/initial.php (added)
-
tags/1.3.0/js (added)
-
tags/1.3.0/js/detect.js (added)
-
tags/1.3.0/js/events.js (added)
-
tags/1.3.0/js/google_ads (added)
-
tags/1.3.0/js/google_ads/consent_mode.js (added)
-
tags/1.3.0/js/google_ads/events.js (added)
-
tags/1.3.0/js/meta (added)
-
tags/1.3.0/js/meta/events.js (added)
-
tags/1.3.0/js/microsoft_ads (added)
-
tags/1.3.0/js/microsoft_ads/consent_mode.js (added)
-
tags/1.3.0/js/microsoft_ads/events.js (added)
-
tags/1.3.0/js/settings (added)
-
tags/1.3.0/js/settings/settings.js (added)
-
tags/1.3.0/readme.txt (added)
-
tags/1.3.0/uninstall.php (added)
-
tags/1.3.0/views (added)
-
tags/1.3.0/views/settings.php (added)
-
trunk/core.php (modified) (5 diffs)
-
trunk/includes/event_capture.php (modified) (3 diffs)
-
trunk/includes/initial.php (modified) (5 diffs)
-
trunk/js/meta/events.js (modified) (11 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/uninstall.php (modified) (1 diff)
-
trunk/views/settings.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
metrion/trunk/core.php
r3290502 r3296257 3 3 * Plugin Name: Metrion 4 4 * Description: Skip manual implementation, sync data directly tailored to destinations like Google Ads and Meta Ads. 5 * Version: 1. 2.05 * Version: 1.3.0 6 6 * Author: Metrion 7 7 * Author URI: https://getmetrion.com … … 15 15 function metrion_register_settings() { 16 16 add_option('metrion_data_collection', 1); // Default data collection (activated) 17 add_option('metrion_customer_api_key', ''); // Default value for customer API key 17 add_option('metrion_api_key', ''); // Default value for customer API key 18 add_option('metrion_api_secret', ''); 19 add_option('metrion_credentials_valid', false); 20 add_option('metrion_installation_id', ''); 18 21 19 22 // Metrion tracking settings 20 add_option('metrion_webhook_destination', 'https:// stream.getmetrion.com/event'); // Webhook URL23 add_option('metrion_webhook_destination', 'https://hub.getmetrion.com/stream/wordpress'); // Webhook URL 21 24 add_option('metrion_api_path_part_1', 'metrion'); // Default path part for the REST API 22 25 add_option('metrion_api_path_part_2','event'); // Default path part suffix for the REST API … … 59 62 add_option('metrion_meta_pixel_id', ''); // Open field for Meta Ads pixel ID 60 63 add_option('metrion_meta_capi_token', ''); // Open field for Meta Ads CAPI 64 add_option('metrion_meta_test_event_code', ''); // Open field for Meta Test event code 65 61 66 62 67 // Microsoft Ads destination options … … 68 73 // Register the Metrion settings 69 74 register_setting('metrion_options_group', 'metrion_data_collection', ['sanitize_callback' => 'rest_sanitize_boolean']); 70 register_setting('metrion_options_group', 'metrion_customer_api_key', ['sanitize_callback' => 'sanitize_text_field']); 75 register_setting('metrion_options_group', 'metrion_api_key', ['sanitize_callback' => 'sanitize_text_field']); 76 register_setting('metrion_options_group', 'metrion_api_secret', ['sanitize_callback' => 'metrion_sanitize_api_secret']); 71 77 72 78 register_setting('metrion_options_group', 'metrion_webhook_destination', ['sanitize_callback' => 'esc_url_raw']); … … 122 128 register_setting('metrion_options_group', 'metrion_microsoft_ads_enable_dynamic_remarketing', ['sanitize_callback' => 'rest_sanitize_boolean']); 123 129 register_setting('metrion_options_group', 'metrion_microsoft_ads_tag_id', ['sanitize_callback' => 'sanitize_text_field']); 124 125 } 130 register_setting('metrion_options_group', 'metrion_meta_test_event_code', ['sanitize_callback' => 'sanitize_text_field']); 131 132 } 133 134 function metrion_sanitize_api_secret($input) { 135 $new_secret = sanitize_text_field($input); 136 $api_key = get_option('metrion_api_key', ''); 137 138 if (!empty($api_key) && !empty($new_secret)) { 139 $response = wp_remote_post('https://dev.getmetrion.com/internal-api/workspaces/installations', [ 140 'body' => json_encode(['key' => $api_key, 'secret' => $new_secret]), 141 'headers' => ['Content-Type' => 'application/json'], 142 ]); 143 144 if (is_wp_error($response)) { 145 add_settings_error( 146 'metrion_api_secret', 147 'api_error', 148 'Error connecting to the API.', 149 'error' 150 ); 151 update_option('metrion_credentials_valid', false); 152 update_option('metrion_installation_id', ''); 153 } else { 154 $status_code = wp_remote_retrieve_response_code($response); 155 if ($status_code === 200) { 156 $body = json_decode(wp_remote_retrieve_body($response), true); 157 if (isset($body['installationId'])) { 158 update_option('metrion_credentials_valid', true); 159 update_option('metrion_installation_id', sanitize_text_field($body['installationId'])); 160 add_settings_error( 161 'metrion_api_secret', 162 'credentials_valid', 163 'Credentials verified successfully. Installation ID: ' . esc_html($body['installationId']), 164 'updated' 165 ); 166 } else { 167 update_option('metrion_credentials_valid', false); 168 update_option('metrion_installation_id', ''); 169 add_settings_error( 170 'metrion_api_secret', 171 'credentials_invalid', 172 'Invalid response from API.', 173 'error' 174 ); 175 } 176 } else { 177 update_option('metrion_credentials_valid', false); 178 update_option('metrion_installation_id', ''); 179 add_settings_error( 180 'metrion_api_secret', 181 'credentials_invalid', 182 'Failed to verify credentials. Please check your key and secret.', 183 'error' 184 ); 185 } 186 } 187 } elseif (empty($api_key) || empty($new_secret)) { 188 update_option('metrion_credentials_valid', false); 189 update_option('metrion_installation_id', ''); 190 add_settings_error( 191 'metrion_api_secret', 192 'missing_credentials', 193 'Both Metrion Key and Secret are required.', 194 'error' 195 ); 196 } 197 198 return $new_secret; 199 } 200 126 201 add_action('admin_init', 'metrion_register_settings'); 127 202 -
metrion/trunk/includes/event_capture.php
r3290502 r3296257 63 63 } 64 64 65 $api_url = get_option('metrion_webhook_destination', 'https:// stream.getmetrion.com/event');65 $api_url = get_option('metrion_webhook_destination', 'https://hub.getmetrion.com/stream/wordpress'); 66 66 $args = array( 67 67 'body' => wp_json_encode($event_data), … … 196 196 return array( 197 197 // Core configuration settings 198 'webhook_url' => get_option('metrion_webhook_destination', 'stream.getmetrion.com/event'), 198 'version' => '1.3.0', 199 'installation_id' => get_option('metrion_installation_id', ''), 200 'webhook_url' => get_option('metrion_webhook_destination', 'https://hub.getmetrion.com/stream/wordpress'), 199 201 'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'), 200 202 'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'), … … 202 204 'cookie_expiration_days' => $cookie_expiration_days, 203 205 'session_cookie_lifetime_minutes' => intval(get_option('metrion_session_cookie_lifetime', 30)), 204 'customer_api_key' => get_option('metrion_customer_api_key', 'key-alfa-100'),205 206 'api_path_part_1' => get_option('metrion_api_path_part_1', 'metrion'), 206 207 'api_path_part_2' => get_option('metrion_api_path_part_2', 'event'), -
metrion/trunk/includes/initial.php
r3290502 r3296257 57 57 return [ 58 58 // Metrion settings 59 'webhook_url' => get_option('metrion_webhook_destination', 'https://stream.getmetrion.com/event'), 59 'version' => '1.3.0', 60 'installation_id' => get_option('metrion_installation_id', ''), 61 'webhook_url' => get_option('metrion_webhook_destination', 'https://hub.getmetrion.com/stream/wordpress'), 60 62 'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'), 61 63 'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'), … … 64 66 'cookie_expiration_days' => $cookie_expiration_days, 65 67 'session_cookie_lifetime_minutes' => intval(get_option('metrion_session_cookie_lifetime', 30)), 66 'customer_api_key' => get_option('metrion_customer_api_key', 'key-alfa-100'),67 68 'api_path_part_1' => get_option('metrion_api_path_part_1', 'metrion'), 68 69 'api_path_part_2' => get_option('metrion_api_path_part_2', 'event'), … … 93 94 'meta_pixel_id' => get_option('metrion_meta_pixel_id', ''), 94 95 'meta_capi_token' => get_option('metrion_meta_capi_token', ''), 96 'meta_test_event_code' => get_option('metrion_meta_test_event_code', ''), 95 97 96 98 'form_tracking' => get_option('metrion_form_tracking', 1), … … 500 502 'api_url' => home_url('/wp-json/' . get_option('metrion_api_path_part_1', 'metrion') . '/' . get_option('metrion_api_path_part_2', 'event') . '/'), 501 503 'debug_mode' => get_option('metrion_debug_mode', '0'), 504 'installation_id' => get_option('metrion_installation_id', ''), 502 505 'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'), 503 506 'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'), … … 525 528 'meta_allow_front_end_pixel_tracking' => get_option('metrion_meta_allow_front_end_pixel_tracking', 0), 526 529 'meta_pixel_id' => get_option('metrion_meta_pixel_id', ''), 530 'meta_test_event_code' => get_option('metrion_meta_test_event_code', ''), 527 531 'purchase_only_tracking' => get_option('metrion_purchase_only_tracking', 1), 528 532 'microsoft_ads_enable_tracking' => get_option('metrion_microsoft_ads_enable_tracking', 0), -
metrion/trunk/js/meta/events.js
r3290502 r3296257 14 14 15 15 // Trigger the initial events 16 fbq('init', window.metrion_api.meta_pixel_id); 16 fbq('init', window.metrion_api.meta_pixel_id, { 17 "external_id": window.metrion.helpers.get_cookie_value((window.metrion_api.user_cookie_name + "_js")) 18 }); 17 19 18 20 // Check broker que for the initial events … … 62 64 if(event_name === "page_view"){ 63 65 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "PageView", { 64 eventID: event_data[window.metrion_api.event_id_name], 65 external_id: event_data[window.metrion_api.user_cookie_name] 66 test_event_code: window.metrion_api.meta_test_event_code 67 }, 68 { 69 eventID: event_data[window.metrion_api.event_id_name] 66 70 }); 67 71 } … … 88 92 89 93 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "Search", { 90 eventID: event_data[window.metrion_api.event_id_name], 91 external_id: event_data[window.metrion_api.user_cookie_name], 94 test_event_code: window.metrion_api.meta_test_event_code, 92 95 search_string: event_data.event_body.search_term, 93 96 content_type: "product", … … 97 100 currency: collective_currency, 98 101 contents: item_contents, 102 }, 103 { 104 eventID: event_data[window.metrion_api.event_id_name] 99 105 }); 100 106 } … … 105 111 if(typeof event_data.event_body.items !== 'undefined' && Array.isArray(event_data.event_body.items) && event_data.event_body.items.length > 0){ 106 112 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "AddToCart", { 107 eventID: event_data[window.metrion_api.event_id_name],113 test_event_code: window.metrion_api.meta_test_event_code, 108 114 content_name: event_data.event_body.items[0].name, 109 115 content_category: event_data.event_body.items[0].category_1, … … 114 120 contents: [{ 115 121 id: event_data.event_body.items[0].id, 116 quantify: event_data.event_body.items[0].quantity 117 }], 118 external_id: event_data[window.metrion_api.user_cookie_name] 122 quantity: event_data.event_body.items[0].quantity 123 }] }, 124 { 125 eventID: event_data[window.metrion_api.event_id_name] 119 126 }); 120 127 } … … 124 131 if(typeof event_data.event_body.items !== 'undefined' && Array.isArray(event_data.event_body.items) && event_data.event_body.items.length > 0){ 125 132 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "ViewContent", { 126 eventID: event_data[window.metrion_api.event_id_name],133 test_event_code: window.metrion_api.meta_test_event_code, 127 134 content_name: event_data.event_body.items[0].name, 128 135 content_category: event_data.event_body.items[0].category_1, … … 133 140 contents: [{ 134 141 id: event_data.event_body.items[0].id, 135 quantify: event_data.event_body.items[0].quantity 136 }], 137 external_id: event_data[window.metrion_api.user_cookie_name] 142 quantity: event_data.event_body.items[0].quantity 143 }] 144 }, 145 { 146 eventID: event_data[window.metrion_api.event_id_name] 138 147 }); 139 148 } … … 158 167 } 159 168 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "InitiateCheckout", { 160 eventID: event_data[window.metrion_api.event_id_name],169 test_event_code: window.metrion_api.meta_test_event_code, 161 170 num_items: item_count, 162 171 content_ids: item_content_ids, 163 172 value: collective_value, 164 173 currency: collective_currency, 165 contents: item_contents, 166 external_id: event_data[window.metrion_api.user_cookie_name] 174 contents: item_contents 175 }, 176 { 177 eventID: event_data[window.metrion_api.event_id_name] 167 178 }); 168 179 } … … 191 202 // Trigger the conversion 192 203 window.fbq('trackSingle', window.metrion_api.meta_pixel_id, "Purchase", { 193 eventID: event_data[window.metrion_api.event_id_name], 194 204 test_event_code: window.metrion_api.meta_test_event_code, 195 205 num_items: item_count, 196 206 content_ids: item_content_ids, … … 198 208 currency: collective_currency, 199 209 contents: item_contents, 200 content_type: "product", 201 202 external_id: event_data[window.metrion_api.user_cookie_name] 210 content_type: "product" 211 }, 212 { 213 eventID: event_data[window.metrion_api.event_id_name] 203 214 }); 204 215 } -
metrion/trunk/readme.txt
r3290502 r3296257 4 4 Requires at least: 3.8 5 5 Tested up to: 6.8 6 Stable tag: 1. 2.06 Stable tag: 1.3.0 7 7 Requires PHP: 7.1 8 8 License: GPLv3 or later … … 87 87 == Changelog == 88 88 89 = 1.3.0 = 90 - Added Metrion authentication with platform 91 89 92 = 1.2.0 = 90 93 - Added support for Elementor webform tracking -
metrion/trunk/uninstall.php
r3290502 r3296257 7 7 // List of all the options created by the plugin 8 8 $options = [ 9 'metrion_customer_api_key', 9 'metrion_api_key', 10 'metrion_api_secret', 11 'metrion_installation_id', 12 'metrion_credentials_valid', 10 13 'metrion_webhook_destination', 11 14 'metrion_api_path_part_1', -
metrion/trunk/views/settings.php
r3290502 r3296257 6 6 <div> 7 7 <h2>Metrion Settings</h2> 8 <p>Version: 1.2.0 </p>9 8 <form method="post" action="options.php"> 10 9 <?php settings_fields('metrion_options_group'); ?> … … 24 23 </tr> 25 24 <tr valign="top"> 26 <th scope="row"><label for="metrion_ customer_api_key">Customer APIKey</label></th>25 <th scope="row"><label for="metrion_api_key">Metrion Key</label></th> 27 26 <td> 28 <input type="text" id="metrion_customer_api_key" name="metrion_customer_api_key" placeholder="mtrn-trial-30day" value="<?php echo esc_attr(get_option('metrion_customer_api_key', 'mtrn-trial-30day')); ?>"/></td> 29 27 <input type="text" id="metrion_api_key" name="metrion_api_key" placeholder="xxx" value="<?php echo esc_attr(get_option('metrion_api_key', 'xxx')); ?>"/></td> 28 29 </tr> 30 <tr valign="top"> 31 <th scope="row"><label for="metrion_api_secret">Metrion Secret</label></th> 32 <td> 33 <input type="text" id="metrion_api_secret" name="metrion_api_secret" placeholder="Metrion Secret" value="<?php echo esc_attr(get_option('metrion_api_secret', '')); ?>"/> 34 <?php 35 $credentials_valid = get_option('metrion_credentials_valid', false); 36 $installation_id = get_option('metrion_installation_id', ''); 37 $api_key = get_option('metrion_api_key', ''); 38 $api_secret = get_option('metrion_api_secret', ''); 39 if ($credentials_valid) { 40 echo '<p style="color: green;">Credentials are valid. Installation ID: ' . esc_html($installation_id) . '</p>'; 41 } elseif (!empty($api_key) && !empty($api_secret)) { 42 echo '<p style="color: red;">Credentials are invalid.</p>'; 43 } else { 44 echo '<p>Enter your credentials to verify.</p>'; 45 } 46 ?> 47 </td> 30 48 </tr> 31 49 </table> … … 47 65 <td> 48 66 <input type="text" id="metrion_webhook_destination" name="metrion_webhook_destination" 49 placeholder="https:// stream.getmetrion.com/event/"50 value="<?php echo esc_attr(get_option('metrion_webhook_destination', 'https:// stream.getmetrion.com/event/')); ?>"67 placeholder="https://hub.getmetrion.com/stream/wordpress" 68 value="<?php echo esc_attr(get_option('metrion_webhook_destination', 'https://hub.getmetrion.com/stream/wordpress')); ?>" 51 69 readonly /> 52 70 </td> … … 339 357 </td> 340 358 </tr> 359 <tr valign="top"> 360 <th scope="row"><label for="metrion_meta_test_event_code">Meta Test event code</label></th> 361 <td> 362 <input type="text" id="metrion_meta_test_event_code" name="metrion_meta_test_event_code" 363 value="<?php echo esc_attr(get_option('metrion_meta_test_event_code', '')); ?>" /> 364 </td> 365 </tr> 341 366 </table> 342 367 <h2>Microsoft Ads specific settings</h2>
Note: See TracChangeset
for help on using the changeset viewer.