Hello @All,
im trying to get a little bit special to work with the piwigo StatisticsPlugin.
I would like to call a small php function from within the piwik javascript code. Could you help me please? I've used the google search for a general help and also for the special callings from a php-function from the javascript code.
Here is an example:
<!-- Plugin Statistics --> <!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "UserID", "<?php $_SERVER['REMOTE_USER']; >?", "visit"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//piwik.domain.de/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 1]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//piwik.domain.de/piwik.php?idsite=nn" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code --> <!-- Plugin Statistics -->
Could you give me please a little advise, how i could call the following part of php Script from within the Javascript code:
_paq.push(["setCustomVariable", 1, "UserID", "<?php $_SERVER['REMOTE_USER']; >?", "visit"]);
Of couse i also studied the Page http://developer.piwik.org/guides/track … variables, but the recommendation from there isn't working within the statistics plugin!
_paq.push(['setDocumentTitle', "<?php echo $myPageTitle ?>"]);
Piwigo version: newest version (i don't see it in the Piwigo GUI)
PHP version: 5.4.44-0+deb7u1
MySQL version: 5.5.44-0+deb7u1
Piwigo URL: http://
Last edited by Blaufotograph (2015-09-05 22:08:47)
Offline
Hello @All,
does maybe anyone have an idea? Is Piwigo filtering this kind of script calls ?
Thanks,
Axel Birndt
Offline
Hello
PHP code is not allowed in the Statistics plugin. Only JavaScript.
Here is what I propose :
I don't exactly know what is "REMOTE_USER", so I'll show you how to use the Piwigo user id instead, you can easily change the data you want (see the code comments)
1. create a personal plugin
to expose the user id somewhere in the page
Go to Plugins->LocalFiles Editor->Personal plugin and enter this
<?php /* Plugin Name: add hidden USER_ID */ add_event_handler('loc_end_page_header', 'add_user_id'); function add_user_id() { global $template, $user; $template->assign('MY_USER_ID', $user['id']); // HERE you can replace $user['id'] by something else $template->set_prefilter('header', 'add_user_id_prefilter', 100); } function add_user_id_prefilter($content) { return $content . "\n" . '<span style="display:none" id="my_user_id">{$MY_USER_ID}</span>'; }
Then activate the plugin in the Plugins management page.
2. In the Statistics input
Replace
"<?php $_SERVER['REMOTE_USER']; >?"
by
document.getElementById('my_user_id').innerHTML
You can enhance the personal plugin with more data ($template->assign + template declaration) and use them in Statistics with document.getElementById(...).innerHTML
Offline
Interesting! Maybe a start to a better integration with Piwik :-)
Offline
mistic100 wrote:
Hello
PHP code is not allowed in the Statistics plugin. Only JavaScript.
Here is what I propose :
I don't exactly know what is "REMOTE_USER", so I'll show you how to use the Piwigo user id instead, you can easily change the data you want (see the code comments)
1. create a personal plugin
to expose the user id somewhere in the page
Go to Plugins->LocalFiles Editor->Personal plugin and enter this
ReplaceCode:
"<?php $_SERVER['REMOTE_USER']; >?"by
Hello Mistic100,
thank you very much for your hint. The 'REMOTE_USER' is the user which has logged in by basic authentication from the webserver (in my case from a Apache Web-Server).
I would like to log the user wich has logged in by Basic Authentication to the Apache.
After creating the the plugin i will put this here into this thread.
I hope i got it running.
regards, Axel
Offline
Hello Mistic100,
Of course the private plugin was created and succesful written.
unfortunately does the code not working.
I've created the the JavascriptCode as shown below:
Is there maybe an error in my generated Javascript:
<!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "UserID", "document.getElementById('my_user_id').innerHTML", "visit"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//piwik.domain.de/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 1]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//piwik.domain.de/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code -->
The generated Javascript code is:
<!-- Plugin Statistics --> <!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "UserID", "document.getElementById('my_user_id').innerHTML", "visit"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//piwik.domain.de/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 1]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//piwik.domain.de/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code --> <!-- Plugin Statistics -->
Now the Javascript Code "document.getElementById('my_user_id').innerHTML" wont be executed and the user-id was not replaced.
I would like to ask you again for a hint.
Thank you very much,
Kind regards Axel
Last edited by Blaufotograph (2015-09-29 22:32:02)
Offline
remove the quotes arround "document.getElementById('my_user_id').innerHTML"
I said
Replace note the quotes, to be removed
"<?php $_SERVER['REMOTE_USER']; >?"
by
document.getElementById('my_user_id').innerHTML
it was not a typo
Offline
mistic100 wrote:
remove the quotes [...]
Code:
document.getElementById('my_user_id').innerHTMLit was not a typo
Yesterday i haven't activated the personal plugin. I've done this now. But the code wont be executed and the variables wasnt replaced.
This is the Javascript Code from the Statistics Plugin:
<!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "UserID", document.getElementById('my_user_id').innerHTML, "visit"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//piwik.domain.de/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 1]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//piwik.domain.de/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code -->
By the way, i couldnt write the real url for the Piwigo Gallery here, because it is a private gallery. currently it is to much work to clone and clean the gallery for public access. I hope you could understand this.
Offline
If you actually have
<span style="display:none" id="my_user_id">something</span>
in the page, there is no reason it does not work
(you won't see the variable being actually replaced in the page, you must check it on Piwik side)
Offline
mistic100 wrote:
If you actually have
Code:
<span style="display:none" id="my_user_id">something</span>in the page, there is no reason it does not work
(you won't see the variable being actually replaced in the page, you must check it on Piwik side)
Hello mistic100,
In my mind the code within the Javascript for the piwik Trackingcode won't or couldn't(??) interpreted or executed.
It this a possible reason ?
The following code is, what i could see via "view page source code" within my newest firefox browser:
<!-- Plugin Statistics --> <!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "UserID", document.getElementById('my_user_id').innerHTML, "visit"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//piwik.domain.de/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 1]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); </script> <noscript><p><img src="//piwik.domain.de/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript> <!-- End Piwik Code --> <!-- Plugin Statistics -->
In my mind the function "document.getElementById('my_user_id').innerHTML" was not executed, or the personal plugin was not called. Of course, i have activated this since my last some answers.
Sorry for the trouble, but i'am not familar with javascript or php code writing. Does Piwigo has a debug or tracking function wich help as a little bit more for the debugging here?
Offline
Hi @All, hello Mistic100,
i have a screenshot, from my generated sourcecode in my site. As i mentioned in my last post, the function wont be executed and the variable wont be replaced.
Could you please have a look at my screenshot?
Last edited by Blaufotograph (2015-10-03 22:31:32)
Offline
as I already said : this is NORMAL, I won't teach you JavaScript here.
now you just have to check on Piwik that the value is here
Offline
mistic100 wrote:
as I already said : this is NORMAL, I won't teach you JavaScript here.
now you just have to check on Piwik that the value is here
Thank you very much. Of course i understand, that you couldn't teach me in Javascript. Please excuse me, if i maybe waste your time. I appreciate your help very much.
I checked now my piwik instance, and found the UserID "3".
Now my next steps will be to find out, how i could find out the real user and translate it to the text interpration.
I hope this thread will help also other users with the same issue.
Kind regards and thank you very much,
Axel Birndt
Offline
plg wrote:
Interesting! Maybe a start to a better integration with Piwik :-)
Hi PLG, hello mistic100,
I've now successful implemented my plugin and changed my parameters to track the HTTP_REMOTE UserID from the Apacheserver too.
Here is the php-code for the personal plugin like described from you, mistic100, and changed from me for my needs:
* plugins/PersonalPlugin/main.inc.php
<?php /* Plugin Name: Personal Plugin to fill in the UserID and the HTTP-User Version: 1.0 Description: Personal Plugin for fill in the UserID and the HTTP-User from the Apache-Server Environment Plugin URI: http://piwigo.org/??? Author: Example from mistic100, extended from blaufotograph Author URI: http://www.2axels-company.de */ /* Plugin Name: add hidden USER_ID */ add_event_handler('loc_end_page_header', 'add_user_id'); add_event_handler('loc_end_page_header', 'add_http_user_id'); function add_user_id() { global $template, $user; $template->assign('MY_USER_ID', $user['username']); // HERE you can replace $user['id'] by something else $template->set_prefilter('header', 'add_user_id_prefilter', 100); } function add_user_id_prefilter($content) { return $content . "\n" . '<span style="display:none" id="my_user_id">{$MY_USER_ID}</span>'; } function add_http_user_id() { global $template, $user; $template->assign('HTTP_USER_ID', $_SERVER['REMOTE_USER']); // HERE you can replace $user['id'] by something else. Additional i'am trying to setup the RemoteUser from the Apache Environment $template->set_prefilter('header', 'add_http_id_prefilter', 100); } function add_http_id_prefilter($content) { return $content . "\n" . '<span style="display:none" id="http_user_id">{$HTTP_USER_ID}</span>'; } ?>
Into the normal Piwik Javascript Tracking code you should fill in the following lines to track the UserID(resp. the logged in user in Piwigo) and the HTTP REMOTE_USER from the Apache Environment:
<!-- Piwik --> <script type="text/javascript"> var _paq = _paq || []; // you can set up to 5 custom variables for each visitor _paq.push(["setCustomVariable", 1, "LoggedInUser", document.getElementById('my_user_id').innerHTML, "visit"]); _paq.push(["setCustomVariable", 2, "HTTPRemoteUser", document.getElementById('http_user_id').innerHTML, "visit"]); _paq.push(['trackPageView']); [...]
Inside Piwik you will see the logged IDs and Users like below:
LoggedInUser : username<x>
HTTPRemoteUser : username<x>
@Plg,
Maybe it is a good idea to create a plugin (maybe especially for Piwik) to setup some user defined php-Variables which could then be used inside the Javascript tracking code or for any other purposes.
My idea is to make it easier to include the values from php Variables. My first painful steps in this way was described above. As i understand your Piwigo Gallery, you do the filtering of any other code, inside the statistics plugin.
Ok, now i'am looking forward expectantly to the future, what you are thinking about this idea ?
Kind regards,
Axel Birndt
Last edited by Blaufotograph (2015-10-06 22:19:23)
Offline
Shrink the personal plugin with:
<?php /* Plugin Name: Personal Plugin to fill in the UserID and the HTTP-User Version: 1.0 Description: Personal Plugin for fill in the UserID and the HTTP-User from the Apache-Server Environment Author: Example from mistic100, extended from blaufotograph Author URI: http://www.2axels-company.de */ add_event_handler('loc_end_page_header', 'add_user_id'); function add_user_id() { global $template, $user; $template->assign('MY_USER_ID', $user['username']); $template->assign('HTTP_USER_ID', $_SERVER['REMOTE_USER']); $template->set_prefilter('header', 'add_user_id_prefilter', 100); } function add_user_id_prefilter($content) { return $content . "\n" . '<span style="display:none" id="my_user_id">{$MY_USER_ID}</span>' . '<span style="display:none" id="http_user_id">{$HTTP_USER_ID}</span>'; } ?>
Offline