Jump to the post that solved this thread.
Not Solved [How To?] Adding tracking code to the AdminCP - Where?
#1
Not Solved Pencil 
Hi,

I would like to add a Piwk tracking code to the Admin CP for a variety of reasons, such as spotting fraudulent activities, monitoring/assessing new staff, etc etc...

However I don't think the Admin CP has templates in the same way the front end does.

My question is: where may I add tracking code? There is a javascript code and a noscript image tracking code.

Thanks!
MyBB Extras = Nope.
Reply
#2
Not Solved
its rather unusual requirement !
anyway, look in file ~/admin/inc/class_page.php#L228
if($mybb->debug_mode)
make empty line above it and there you can add required codes with echo statements
echo "<script> ____________________ </script>";

however please ensure that you add only trusted script codes
Reply
#3
Not Solved
Hi,

I've just tried this and unfortunately I'm now getting errors within the admincp:

Parse error: syntax error, unexpected 'text' (T_STRING), expecting ',' or ';' in /home/[domain]/public_html/web/admin/inc/class_page.php on line 228

The entire file: http://pastie.org/private/lb9d2uxzkrr7grxspuz3q

Even Notepad++'s syntax highlighting doesn't like the tracking code I put in where most text under the code is gray; even after making it all one line, it still generates errors.

The tracking code is:

<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["setDomains", ["*.boa-clan.com"]]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="TRACKING URL HERE";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 3]);
    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>

Changing "<script type="text/javascript">" to "<script>" also did nothing.

I even tried using the image tracking fallback but that didn't work either
MyBB Extras = Nope.
Reply
#4
Not Solved
please check if below code works
echo '<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(["setDomains", ["*.boa-clan.com"]]);
  _paq.push([\'trackPageView\']);
  _paq.push([\'enableLinkTracking\']);
  (function() {
    var u="//URL-HERE";
    _paq.push([\'setTrackerUrl\', u+\'piwik.php\']);
    _paq.push([\'setSiteId\', 3]);
    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>'; 
Reply
#5
Not Solved
Hi,

Excellent, works perfectly and the syntax highlighting shows the entire script in grey, which is how it should have been. The tracking works great. Thank you so much! Two more things:

1) Would you mind sharing what you did so I can learn please? I've compared my and your code and can't see an obvious difference?

2) In which page and where would I need to put the code to cover the login page?

Thanks!
MyBB Extras = Nope.
Reply
#6
Not Solved
(2016-06-04, 12:34 AM)groovybluedog Wrote: 1) Would you mind sharing what you did so I can learn please? I've compared my and your code and can't see an obvious difference?
Apostrophes (') within the JavaScript code needed to be escaped with a backslash (\'), since they are used to enclose a PHP string (see https://secure.php.net/manual/en/languag...string.php).

Quote:2) In which page and where would I need to put the code to cover the login page?
Try before the </body> tag in https://github.com/mybb/mybb/blob/mybb_1...e.php#L496
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)