Plugin Directory

Changeset 3296257


Ignore:
Timestamp:
05/19/2025 08:02:33 AM (10 months ago)
Author:
metriondev
Message:

Version 1.3.0

Location:
metrion
Files:
27 added
7 edited

Legend:

Unmodified
Added
Removed
  • metrion/trunk/core.php

    r3290502 r3296257  
    33* Plugin Name:          Metrion
    44* Description:          Skip manual implementation, sync data directly tailored to destinations like Google Ads and Meta Ads.
    5 * Version:              1.2.0
     5* Version:              1.3.0
    66* Author:               Metrion
    77* Author URI:           https://getmetrion.com
     
    1515function metrion_register_settings() {
    1616    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', '');
    1821
    1922    // Metrion tracking settings
    20     add_option('metrion_webhook_destination',  'https://stream.getmetrion.com/event');      // Webhook URL
     23    add_option('metrion_webhook_destination',  'https://hub.getmetrion.com/stream/wordpress');      // Webhook URL
    2124    add_option('metrion_api_path_part_1', 'metrion');                                       // Default path part for the REST API
    2225    add_option('metrion_api_path_part_2','event');                                          // Default path part suffix for the REST API
     
    5962    add_option('metrion_meta_pixel_id', '');                                                // Open field for Meta Ads pixel ID
    6063    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
    6166
    6267    // Microsoft Ads destination options
     
    6873    // Register the Metrion settings
    6974    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']);
    7177
    7278    register_setting('metrion_options_group', 'metrion_webhook_destination', ['sanitize_callback' => 'esc_url_raw']);
     
    122128    register_setting('metrion_options_group', 'metrion_microsoft_ads_enable_dynamic_remarketing', ['sanitize_callback' => 'rest_sanitize_boolean']);
    123129    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
     134function 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
    126201add_action('admin_init', 'metrion_register_settings');
    127202
  • metrion/trunk/includes/event_capture.php

    r3290502 r3296257  
    6363    }
    6464
    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');
    6666    $args = array(
    6767        'body'        => wp_json_encode($event_data),
     
    196196    return array(
    197197        // 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'),
    199201        'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'),
    200202        'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'),
     
    202204        'cookie_expiration_days' => $cookie_expiration_days,
    203205        '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'),
    205206        'api_path_part_1' => get_option('metrion_api_path_part_1', 'metrion'),
    206207        'api_path_part_2' => get_option('metrion_api_path_part_2', 'event'),
  • metrion/trunk/includes/initial.php

    r3290502 r3296257  
    5757    return [
    5858        // 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'),
    6062        'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'),
    6163        'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'),
     
    6466        'cookie_expiration_days' => $cookie_expiration_days,
    6567        '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'),
    6768        'api_path_part_1' => get_option('metrion_api_path_part_1', 'metrion'),
    6869        'api_path_part_2' => get_option('metrion_api_path_part_2', 'event'),
     
    9394        'meta_pixel_id' => get_option('metrion_meta_pixel_id', ''),
    9495        'meta_capi_token' => get_option('metrion_meta_capi_token', ''),
     96        'meta_test_event_code' => get_option('metrion_meta_test_event_code', ''),
    9597
    9698        'form_tracking' => get_option('metrion_form_tracking', 1),
     
    500502        'api_url' => home_url('/wp-json/' . get_option('metrion_api_path_part_1', 'metrion') . '/' . get_option('metrion_api_path_part_2', 'event') . '/'),
    501503        'debug_mode' => get_option('metrion_debug_mode', '0'),
     504        'installation_id' => get_option('metrion_installation_id', ''),
    502505        'user_cookie_name' => get_option('metrion_user_cookie_name', 'mtrn_uid'),
    503506        'session_cookie_name' => get_option('metrion_session_cookie_name', 'mtrn_sid'),
     
    525528        'meta_allow_front_end_pixel_tracking' => get_option('metrion_meta_allow_front_end_pixel_tracking', 0),
    526529        'meta_pixel_id' => get_option('metrion_meta_pixel_id', ''),
     530        'meta_test_event_code' => get_option('metrion_meta_test_event_code', ''),
    527531        'purchase_only_tracking' => get_option('metrion_purchase_only_tracking', 1),
    528532        'microsoft_ads_enable_tracking' => get_option('metrion_microsoft_ads_enable_tracking', 0),
  • metrion/trunk/js/meta/events.js

    r3290502 r3296257  
    1414
    1515            // 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            });
    1719
    1820            // Check broker que for the initial events
     
    6264        if(event_name === "page_view"){
    6365            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]
    6670            });
    6771        }
     
    8892
    8993            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,
    9295                search_string: event_data.event_body.search_term,
    9396                content_type: "product",
     
    97100                currency: collective_currency,
    98101                contents: item_contents,         
     102            },
     103            {
     104                eventID: event_data[window.metrion_api.event_id_name]
    99105            });
    100106        }         
     
    105111            if(typeof event_data.event_body.items !== 'undefined' && Array.isArray(event_data.event_body.items) && event_data.event_body.items.length > 0){
    106112                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,
    108114                    content_name: event_data.event_body.items[0].name,
    109115                    content_category: event_data.event_body.items[0].category_1,
     
    114120                    contents: [{
    115121                        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]
    119126                });   
    120127            }       
     
    124131            if(typeof event_data.event_body.items !== 'undefined' && Array.isArray(event_data.event_body.items) && event_data.event_body.items.length > 0){
    125132                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,
    127134                    content_name: event_data.event_body.items[0].name,
    128135                    content_category: event_data.event_body.items[0].category_1,
     
    133140                    contents: [{
    134141                        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]
    138147                });
    139148            }
     
    158167                }
    159168                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,
    161170                    num_items: item_count,
    162171                    content_ids: item_content_ids,
    163172                    value: collective_value,
    164173                    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]
    167178                });
    168179            }
     
    191202                // Trigger the conversion
    192203                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,
    195205                    num_items: item_count,
    196206                    content_ids: item_content_ids,
     
    198208                    currency: collective_currency,
    199209                    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]
    203214                });
    204215            }
  • metrion/trunk/readme.txt

    r3290502 r3296257  
    44Requires at least: 3.8
    55Tested up to: 6.8
    6 Stable tag: 1.2.0
     6Stable tag: 1.3.0
    77Requires PHP: 7.1
    88License: GPLv3 or later
     
    8787== Changelog ==
    8888
     89= 1.3.0 =
     90- Added Metrion authentication with platform
     91
    8992= 1.2.0 =
    9093- Added support for Elementor webform tracking
  • metrion/trunk/uninstall.php

    r3290502 r3296257  
    77// List of all the options created by the plugin
    88$options = [
    9     'metrion_customer_api_key',
     9    'metrion_api_key',
     10    'metrion_api_secret',
     11    'metrion_installation_id',
     12    'metrion_credentials_valid',
    1013    'metrion_webhook_destination',
    1114    'metrion_api_path_part_1',
  • metrion/trunk/views/settings.php

    r3290502 r3296257  
    66<div>
    77    <h2>Metrion Settings</h2>
    8     <p>Version: 1.2.0 </p>
    98    <form method="post" action="options.php">
    109        <?php settings_fields('metrion_options_group'); ?>
     
    2423            </tr>
    2524            <tr valign="top">
    26                 <th scope="row"><label for="metrion_customer_api_key">Customer API Key</label></th>
     25                <th scope="row"><label for="metrion_api_key">Metrion Key</label></th>
    2726                <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>
    3048            </tr>
    3149        </table>
     
    4765                    <td>
    4866                        <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')); ?>"
    5169                               readonly />
    5270                    </td>
     
    339357                    </td>
    340358                </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>
    341366            </table>
    342367            <h2>Microsoft Ads specific settings</h2>
Note: See TracChangeset for help on using the changeset viewer.