Jump to content

Matomo - A Mixed Blessing?


iwato

Recommended Posts

BACKGROUND:  It would be a long exercise in the grammar of the English language to explain what you can more readily understand by going directly to the relevant pages for which I provide the needed annotation below.

gate7.html

On this page you will find code that is identical in structure to six other pages similarly organized but with different content called gate1.html, gate2.html, gate3.html, gate4.html, gate5.html, gate6.html.  The Javascript on this page and the other aforementioned pages performs two important functions:  one, call a jQuery plug-in called $.colorbox that creates a gallery of iframes; and two, send an HTTP request to the Matomo application signalling a change of iframe.  In addition, the gallery in question consists of four pages called gate7a.html, gate7b.html, gate7c.html, and gate7d.php.  It should be noted that the other aforementioned six pages including gate1.html through gate6.html all perform similar tasks using nearly identical code.  What makes gate7.html is the extension of the last iframe that it calls -- namely, gate7d.php.  None of the other pages call an iframe with a PHP extension. 

overview.html

After landing on this page you will find in the navigation bar on your left several options under the subheading Visitor Profile. I would like to draw your attention to two of them -- namely, Event Profiles and Splash Panel.  These two panels report similar information obtained from the Matomo database -- albeit via differently constructed PHP cURL calls.

Event Profiles:   Once the panel fills, click anywhere where it says by Category and what will appear is an entry for all of the seven gates, but the one in question.

Splash Panel:   Click on any of the items under the heading By Category, and you will discover the same.  The absence of data for the Gate Seven gallery.  Click on any of the items under the heading By Named Event, and you will discover that the Javascript for Matomo is collecting the desired data.  Indeed, you will find listed gate7a, gate7d, and title 7;  all of these pages are tracked with the same category tag -- namely, Gate Seven.

CAUTION:  The Matomo application is extremely slow in my current server environment.  You must be patient for the data to fill.  Soon, I will have upgraded to a scalable cloud with my own dedicated IP address, and this problem is expected to go away.  Also, note that the splash panel consists of some 47 individually constructed webpages eight of which contain Javascript using the same  $.colorbox plug-in. 

INSTRUCTION:  After you load the overview.html page open your web console.  Then, click on the heading Splash Panel under Visitor Profile, open your Network tab in your web console, and look for a file called sevengates_splashpanel.php.  Check the AJAX parameters  sent to this page and notice that Gate Seven is among them.  Then, check the pages Response section and notice the format of the 21 returned items.  The pattern object, object, array occurs six times.  For the last three items -- what should contain the information from Gate Seven -- are three empty arrays.

QUESTION:  How would you explain the aforementioned anomaly of three empty arrays?

Roddy

 

 

 

Link to comment
Share on other sites

If you can find something wrong with it I would be grateful.  I can see nothing.  I will even reproduce the value of the $url variable for you.

https://.../index.php?module=API&method=API.getBulkRequest&format=json&token_auth=...&urls[0]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20One&urls[1]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20One&urls[2]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20One&urls[3]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Two&urls[4]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Two&urls[5]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Two&urls[6]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Three&urls[7]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Three&urls[8]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Three&urls[9]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Four&urls[10]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Four&urls[11]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Four&urls[12]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Five&urls[13]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Five&urls[14]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Five&urls[15]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Six&urls[16]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Six&urls[17]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Six&urls[18]=method%3DEvents.getCategory%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Seven&urls[19]=method%3DEvents.getAction%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Seven&urls[20]=method%3DEvents.getName%26idSite%3D1%26period%3Dyear%26date%3Dtoday%26expanded%3D1%26segment%3DeventCategory%3D%3DGate%20Seven

Roddy

Link to comment
Share on other sites

<?php
	ini_set('log_errors', 1);
	ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');
	ini_set('html_errors', 0);
	ini_set('display_errors', 0);
	error_reporting(E_ALL);
	if (isset($_POST['methodName'])) {
		/*****************************************************
		  The set_url_request() Function
		*****************************************************/
		function set_url_request($method, array $params, $event_category) {
			$request = "method=" . $method;
			$segment_str = '';
			if ($event_category == '') {
				foreach ($params as $param) {
					$request .= "&" . $param;
				}
			} else {
				(string) $segment_str = "segment=" . $event_category;
				array_push($params, $segment_str);
				foreach ($params as $param) {
					$request .= "&" . $param;
				}
			}
			return rawurlencode($request);
		}
		/*****************************************************
		  Intialization of Key Variables
		*****************************************************/
		$result = '';
		$query_str = '';
		$i = 0;
		$token_auth = '...';
		$segment_str = '';
		$categories = array();
		$event_category = '';
		$params = array();
		/*****************************************************
		  Event Segmentation
		*****************************************************/		
 		if (isset($_POST['eventCategory'])) {
 			foreach ($_POST['eventCategory'] as $event_category) {
 				$event_category = filter_var($event_category, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
 				$event_category = "eventCategory==" . $event_category;
				foreach ($_POST['methodName'] as $method) {
					$method = filter_var($method, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
					if ($method == '_getCategory') {
						$method = "Events." . substr($method, 1);			
						$params = array("idSite=1","period=year","date=today","expanded=1");
						$query_str = set_url_request($method, $params, $event_category);
						$sub_url .= "&urls[" . $i++ . "]=" . $query_str;
					}
					if ($method == '_getAction') {
						$method = "Events." . substr($method, 1);			
						$params = array("idSite=1","period=year","date=today","expanded=1");
						$query_str = set_url_request($method, $params, $event_category);
						$sub_url .= "&urls[" . $i++ . "]=" . $query_str;
					}				
					if ($method == '_getName') {
						$method = "Events." . substr($method, 1);			
						$params = array("idSite=1","period=year","date=today","expanded=1");
						$query_str = set_url_request($method, $params, $event_category);
						$sub_url .= "&urls[" . $i++ . "]=" . $query_str;
					}				
				}
			}
			$url = "https://...index.php";
			$url .= "?module=API";
			$url .= "&method=API.getBulkRequest";
			$url .= "&format=json";
			$url .= "&token_auth=$token_auth";
			$url .= $sub_url;
 		}
//  		echo $url;
		/*****************************************************
		  Send the Bulk Request
		*****************************************************/		
		$curl_request = curl_init();
		curl_setopt($curl_request, CURLOPT_URL, $url);
		curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
		$result = json_decode(curl_exec($curl_request));
		if(curl_errno($curl_request)) {
			echo 'Curl error: ' . curl_error($curl_request);
		}
		curl_close($curl_request);
		/*****************************************************
		  JSON Encode the Returned Request and Display It
		*****************************************************/		
 		echo json_encode($result);
 	}
?>

Roddy

Link to comment
Share on other sites

Some new light has been shed on the problem!

By sorting the gate categories and named events by gate number in the Visitor Profile / Splash Panel I have discovered that the files related to Gate Seven appear exclusively with those of Gate Two and that the data associated solely with gate7.html  is missing.

Roddy

Link to comment
Share on other sites

Yes, the code and the associated URL and query string  are what create the series of objects and arrays in the uniform pattern expected up until the data for Gate Seven is requested where upon three empty arrays appear instead of two filled objects and one filled array.  Please follow the links that I provided and read my commentary else you will be stabbing in the dark.

Roddy

Link to comment
Share on other sites

So, the json_encode line at the end of the code you posted is what is outputting the structure that you're seeing in the developer tools?  So, the data is coming from that cURL request, and you're wondering why that API is returning empty arrays?

Link to comment
Share on other sites

Yes, in part.  The matter, however, is more complex.  It is not only that the arrays for the Gate Seven query are returned empty, but that they are returned at all. For, the queries for each of the other gates return two objects and an array, rather than three arrays.  Then, there is the more recently discovered confusion about the queried data: although a portion of the data for Gate Seven is returned, it is returned with the query for Gate Two.  It is all too bizaare!

Roddy

Link to comment
Share on other sites

The bizarre character has magically disappeared, but with not without a trace.  For, I now see where a correction that I made in regard to the coding of the Gate Seven webpages has likely made a difference.  For now, Gate Seven is working appropriately, but the Gate Seven data still appears under Gate Two.  I will likely have to go into the Matomo database and remove it manually.

The magical nature of what has occurred is apparently created by a Matomo time lag.  What it calls today is actually yesterday.  Another Matomo mystery that I will someday have to address.  In any case,  I am not as bad a coder as I sometimes think myself to be.  Then too, it was never my goal to become one.  I am becoming one by default.  If Grammar Captive does not sail, then I can write code manuals and help others to overcome the frustration that Matomo has created for me.

Have a great day!

And, once again, thank you for your patience.

Roddy

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...