Plugin Directory

Changeset 3143555


Ignore:
Timestamp:
08/29/2024 10:54:24 AM (19 months ago)
Author:
davidfull
Message:

Implementation of google analytics to the wordpress

Location:
setmore-appointments/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • setmore-appointments/trunk/readme.txt

    r3072242 r3143555  
    11=== Plugin Name ===
    22
    3 Contributors: Anitha/Rajesh
     3Contributors: Anitha/Rajesh/Sankavi
    44Tags: Free, appointments, appointment, scheduling, software, booking, calendar, agenda, management, online, diary, widget, Setmore
    55Requires at least: 3.7.2
    6 Tested up to: 6.5.2
    7 Stable tag: 12.1
     6Tested up to: 6.6.1
     7Stable tag: 12.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • setmore-appointments/trunk/script/setmoreFormScript.js

    r2721397 r3143555  
    6666        })
    6767    })
     68   
     69    async function sendAnalytics(bookingpage, event) {
     70        const currentTimestampMicros = Date.now() * 1000;
     71        const companyKey = bookingpage.split('/').pop();
     72        const measurementId = `G-QGCR29L2YV`;
     73        const apiSecret = `c8RPSMB0SSyNd8XfOonPBg`;
     74        const userType = event.target.id === "signup" ? "new_customer" : "customer";
     75        try {
     76            const response = await fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`, {
     77                method: "POST",
     78                body: JSON.stringify({
     79                    "client_id": companyKey,
     80                    "timestamp_micros": currentTimestampMicros,
     81                    "non_personalized_ads": false,
     82                    "events": [
     83                        {
     84                            "name": "wordpress_plugin_successful_connection",
     85                            "params": {
     86                                "company_id": companyKey,
     87                                "User_type": userType,
     88                                "Brand": "Setmore"
     89                            }
     90                        }
     91                    ]
     92                })
     93            });
     94
     95            if (response.status === 204) {
     96                console.log("Analytics data sent successfully");
     97            } else {
     98                console.error("Unexpected response:", response.status, response.statusText);
     99            }
     100        } catch (error) {
     101            console.error("Error sending analytics data:", error);
     102        }
     103    }
     104   
    68105    function saveBookingPageConfiguration(setmoreBookingPageURl,languageOption,version){
    69106        if(setmoreBookingPageURl){
     
    109146                document.querySelector("#connectBlock").style.display = "none";
    110147                saveBookingPageConfiguration(urlParams.get("bookingpageurl"),"English",urlParams.get("version"));
     148                sendAnalytics(urlParams.get("bookingpageurl"), event);
    111149                window.clearInterval(pollTimer);
    112150                popupWindow.close();
  • setmore-appointments/trunk/setmore.php

    r3072242 r3143555  
    2020{
    2121  /* Deletes the database field */
     22  $booking_page_url = get_option('setmore_booking_page_url');
     23
     24  // Send the deactivation event to Google Analytics with the booking page URL
     25  send_user_analytics($booking_page_url);
    2226  delete_option('setmore_booking_page_url');
    2327  delete_option('languageOption');
    2428  delete_option('setmore_booking_page_version');
     29}
     30
     31function send_user_analytics($booking_page_url)
     32{
     33  if ($booking_page_url) {
     34    $parsed_url = parse_url($booking_page_url, PHP_URL_PATH);
     35    $segments = explode('/', rtrim($parsed_url, '/'));
     36    $companyKey = array_pop($segments);
     37
     38    $url = 'https://www.google-analytics.com/mp/collect?api_secret=c8RPSMB0SSyNd8XfOonPBg&measurement_id=G-QGCR29L2YV';
     39    $body = array(
     40      'client_id' => $companyKey,
     41      'timestamp_micros' => round(microtime(true) * 1000000),
     42      'non_personalized_ads' => false,
     43      'events' => array(
     44        array(
     45          'name' => 'wordpress_plugin_deactivated',
     46          'params' => array(
     47            'Company' => $companyKey,
     48            'Brand' => 'Setmore',
     49          ),
     50        ),
     51      ),
     52    );
     53
     54    $args = array(
     55      'method' => 'POST',
     56      'headers' => array('Content-Type' => 'application/json'),
     57      'body' => json_encode($body),
     58    );
     59
     60    $request = wp_remote_post($url, $args);
     61
     62    if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 204) {
     63      error_log(print_r($request, true));
     64    }
     65
     66  }
    2567}
    2668
Note: See TracChangeset for help on using the changeset viewer.