Skip to content

Commit

Permalink
SP 4.11.0: google analytics quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sendtogeo committed Sep 5, 2024
1 parent f64c9ef commit 852d059
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
7 changes: 6 additions & 1 deletion controllers/googleapi.ctrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ function getanalyticWebsitesPropertyIds($userId) {
$websites = array();
$client = $this->getAuthClient($userId);

// if error occured
if (!is_object($client)) {
return [FALSE, $websites, $client];
}

// Create a Google_Service_Analytics object
$analytics = new Google_Service_Analytics($client);

Expand Down Expand Up @@ -269,7 +274,7 @@ function getanalyticWebsitesPropertyIds($userId) {
}
}

return $websites;
return [TRUE, $websites, "success"];
}

// Function to get GA4 properties
Expand Down
21 changes: 16 additions & 5 deletions controllers/website.ctrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,8 @@ function syncGoogleAnalyticProperties($userId) {
$propertyList = createSelectList($analyticList, "ALL", 'property_id');

$GoogleCtrl = new GoogleAPIController();
$result = $GoogleCtrl->getanalyticWebsitesPropertyIds($userId);
if(!empty($result)) {
[$status, $result, $errMsg] = $GoogleCtrl->getanalyticWebsitesPropertyIds($userId);
if($status && !empty($result)) {
foreach ($result as $data) {
$propertyId = $data['property_id'];

Expand Down Expand Up @@ -989,14 +989,25 @@ function syncGoogleAnalyticProperties($userId) {
}
}
}

return [$status, $errMsg];
}

function fetchGoogleAnalyticProperties() {
$response = ['status' => 0, 'data' => [], 'msg' => "API Error"];
$userId = isLoggedIn();
$this->syncGoogleAnalyticProperties($userId);

$propertyList = $this->__getAllAnalyticProperties(TRUE);
return $propertyList;
// sync google analytics properties using the connectin
[$status, $errMsg] = $this->syncGoogleAnalyticProperties($userId);
if ($status) {
$propertyList = $this->__getAllAnalyticProperties(TRUE);
$response['data'] = $propertyList;
$response['status'] = TRUE;
} else {
$response['msg'] = $errMsg;
}

return $response;
}

function __getUserAnalyticProperties($userId) {
Expand Down
3 changes: 2 additions & 1 deletion themes/classic/views/website/edit_website.ctp.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@

$("#connection_refresh_content").html('<span class="text-success form-success"><i class="ri-checkbox-circle-line"></i>Google Analytics Properties Synced.</span>');
} else {
$("#connection_refresh_content").html('<span class="text-danger form-error"><i class="ri-error-warning-line"></i>Failed to Sync Google Analytics Properties</span>');
$("#connection_refresh_content").html('<span class="text-danger form-error"><i class="ri-error-warning-line"></i>'+ response.msg +'</span>');
}
},
beforeSend: function() {
$('#connection_refresh_loading').show();
$("#connection_refresh_content").html('');
},
error: function(jqXHR, textStatus, errorThrown) {
$("#connection_refresh_content").show();
Expand Down
3 changes: 2 additions & 1 deletion themes/simple/views/website/edit_website.ctp.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@

$("#connection_refresh_content").html('<span class="text-success form-success"><i class="ri-checkbox-circle-line"></i>Google Analytics Properties Synced.</span>');
} else {
$("#connection_refresh_content").html('<span class="text-danger form-error"><i class="ri-error-warning-line"></i>Failed to Sync Google Analytics Properties</span>');
$("#connection_refresh_content").html('<span class="text-danger form-error"><i class="ri-error-warning-line"></i>'+ response.msg +'</span>');
}
},
beforeSend: function() {
$('#connection_refresh_loading').show();
$("#connection_refresh_content").html('');
},
error: function(jqXHR, textStatus, errorThrown) {
$("#connection_refresh_content").show();
Expand Down
4 changes: 2 additions & 2 deletions websites.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
break;

case "fetchgoogleanalytics":
$propertyList = $controller->fetchGoogleAnalyticProperties();
print json_encode(['status' => 1, 'data' => $propertyList]);
$response = $controller->fetchGoogleAnalyticProperties();
print json_encode($response);
break;

default:
Expand Down

0 comments on commit 852d059

Please sign in to comment.