-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking pixel : error 500 in mono language setups #44
Comments
Hi, indeed, there's an issue : the plugin is not loaded when loading the config file : As a temp workaround, you can add this in the top of your config file (correct the path if needed!) : |
Great, this allows me to change the setting in Still getting 500 error for the actual tracking pixel though. |
Are you trying in Kirby 3 ? On my side it's working in the starterkit. (4 is not yet supported) |
Weird, I'm using Starterkit kirby3-simplestats/src/config/routes.php Lines 18 to 24 in eacec7a
kirby3-simplestats/src/models/SimpleStats.php Lines 43 to 77 in eacec7a
|
Same issue with v3.9.1 Can't see anything after I put in the <?php
namespace daandelange\SimpleStats;
//return (false===option('daandelange.simplestats.tracking.onLoad', true))?[]:[
//return (SimpleStatsTrackingMode::OnImage===option('daandelange.simplestats.tracking.method', SimpleStatsTrackingMode::OnLoad))?[]:[
//var_dump(option('daandelange.simplestats.tracking.method')); die();
return [
// Intercept counter pixel on home page
[
'pattern' => 'counter.png',
'language' => '*',
'action' => function ($language) {
die('route intercept before');
return SimpleStats::trackPageAndServeImageResponse( site()->homePage() );
die('route intercept after');
},
],
// On all other pages
[
'pattern' => '(:all)/counter.png',
'language' => '*',
'action' => function ($language, $id) {
die('route intercept all before');
return SimpleStats::trackPageAndServeImageResponse( page($id) );
die('route intercept all after');
},
],
]; // Generates a router response for serving the tracker image
public static function trackPageAndServeImageResponse(Page $page){
die('trackPageAndServeImageResponse');
// Correct tracking method ?
if( SimpleStatsTrackingMode::OnImage === option('daandelange.simplestats.tracking.method', SimpleStatsTrackingMode::OnLoad) ){
// Any tracking feature is enabled ?
if(
true===option('daandelange.simplestats.tracking.enableDevices' , true) ||
true===option('daandelange.simplestats.tracking.enableVisits' , true) ||
true===option('daandelange.simplestats.tracking.enableReferers', true) ||
true===option('daandelange.simplestats.tracking.enableVisitLanguages', true)
){
// Does the page exist ?
if( $page && $page->exists() && $page->isPublished() ){
SimpleStats::safeTrack( $page->id() );
//return var_dump(SimpleStats::safeTrack( $page->id() ));
die('image generation before');
return new Response(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII='), 'image/png', 200);
//header('Content-Type: image/png');
//header("Content-type: image/png");
//echo base64_decode('image/png;base64,'); // Smallest transparent PNG
//echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII='); // Smallest transparent PNG
//header("Content-type: image/gif");
//echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='); // Smallest transparent GIF
//echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); // Smallest transparent GIF
//exit;
die('image generation after');
}
}
// Unknown kirby page or nothing to track, return 404
return new \Kirby\Exception\ErrorPageException(['httpCode'=>410]); // Gone / Removed (with error page)
}
return new \Kirby\Exception\ErrorPageException(['httpCode'=>404]); // Not found (with error page)
//return new Response(null, null, 410); // Gone / Removed (no page is served)
//return false; // generates error page
} |
Btw. are you scrolling down the page? The lazy loading means the browser won't try to load the image until you scroll down some ways. |
Yes, my image gets loaded without scrolling, I see a 1x1 image here for example : But wait, I think I haven't tested in mono-language starterkit (mine is multilang), and there is a language argument in Edit: // Single language
[
'pattern' => 'counter.png',
'action' => function () {
return SimpleStats::trackPageAndServeImageResponse( site()->homePage() );
},
],
[
'pattern' => '(:all)/counter.png',
'action' => function ($id) {
return SimpleStats::trackPageAndServeImageResponse( page($id) );
},
], This (above) is the single language alternative you can use as a quickfix replacement, but Im not sure how to define a combined one; adding both multi+single routes breaks multilang. Not sure how to fix this the intended kirby way. |
Great! It's working now with the single language code snippet. Let me know if you want me to close the issue or leave it open. |
I'll leave it open as this needs to be fixed, thanks for your reports :) |
Tried with starterkit v3.9.8 and v4.0.3
First I tried to set options like indicated in the docs:
PHP promptly crashed...
I ended up changing the setting directly in
src/config/options.php
Then I put
<?= $page->simpleStatsImage() ?>
right before the</body>
tag, which generates the following:<img alt="simplestats counter pixel" class="simplestats-image" height="1" loading="lazy" src="http://localhost:81/starterkit-4.0.3/notes/counter.png" style="position: absolute; right: 0; pointer-events: none; height: 1px; width: 1px; opacity: 0;" width="1">
The src URL is the page URL +
/counter.png
However it fails to load and returns 500 error in the dev console, I'm assuming this is not the intended behavior and that tracking failed.
The text was updated successfully, but these errors were encountered: