Skip to content

Commit

Permalink
fix: matomo config for obf, opf, opff
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Oct 29, 2024
1 parent 953851f commit 33bed39
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
24 changes: 22 additions & 2 deletions lib/ProductOpener/Config_obf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BEGIN {
$memd_servers
$google_analytics
$analytics
$thumb_size
$crop_size
Expand Down Expand Up @@ -270,7 +270,27 @@ $small_size = 200;
$display_size = 400;
$zoom_size = 800;

$google_analytics = <<HTML
$analytics = <<HTML
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.openbeautyfacts.org"]);
_paq.push(["setDomains", ["*.openbeautyfacts.org"]]);
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.openfoodfacts.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '10']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//analytics.openfoodfacts.org/matomo.php?idsite=10&amp;rec=1" style="border:0;" alt="" /></p></noscript>
HTML
;

Expand Down
4 changes: 2 additions & 2 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BEGIN {
$memd_servers
$google_analytics
$analytics
$thumb_size
$crop_size
Expand Down Expand Up @@ -485,7 +485,7 @@ $small_size = 200;
$display_size = 400;
$zoom_size = 800;

$google_analytics = <<HTML
$analytics = <<HTML
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
Expand Down
24 changes: 22 additions & 2 deletions lib/ProductOpener/Config_opf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BEGIN {
$memd_servers
$google_analytics
$analytics
$thumb_size
$crop_size
Expand Down Expand Up @@ -268,7 +268,27 @@ $small_size = 200;
$display_size = 400;
$zoom_size = 800;

$google_analytics = <<HTML
$analytics = <<HTML
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.openproductsfacts.org"]);
_paq.push(["setDomains", ["*.openproductsfacts.org"]]);
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.openfoodfacts.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '11']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//analytics.openfoodfacts.org/matomo.php?idsite=11&amp;rec=1" style="border:0;" alt="" /></p></noscript>
HTML
;

Expand Down
24 changes: 22 additions & 2 deletions lib/ProductOpener/Config_opff.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BEGIN {
$memd_servers
$google_analytics
$analytics
$thumb_size
$crop_size
Expand Down Expand Up @@ -270,7 +270,27 @@ $small_size = 200;
$display_size = 400;
$zoom_size = 800;

$google_analytics = <<HTML
$analytics = <<HTML
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.openpetfoodfacts.org"]);
_paq.push(["setDomains", ["*.openpetfoodfacts.org"]]);
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//analytics.openfoodfacts.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '9']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//analytics.openfoodfacts.org/matomo.php?idsite=9&amp;rec=1" style="border:0;" alt="" /></p></noscript>
HTML
;

Expand Down
9 changes: 1 addition & 8 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7483,15 +7483,8 @@ sub display_page ($request_ref) {
$site_name .= " - " . lang_in_other_lc($request_lc, "producers_platform");
}

# Override Google Analytics from Config.pm with server_options
# defined in Config2.pm if it exists

if (exists $server_options{google_analytics}) {
$google_analytics = $server_options{google_analytics};
}

$template_data_ref->{styles} = $request_ref->{styles};
$template_data_ref->{google_analytics} = $google_analytics;
$template_data_ref->{analytics} = $analytics;
$template_data_ref->{bodyabout} = $request_ref->{bodyabout};
$template_data_ref->{site_name} = $site_name;

Expand Down
2 changes: 1 addition & 1 deletion templates/web/common/site_layout.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[% lang("css") %]
[% styles %]
</style>
[% google_analytics %]
[% analytics %]
</head>
<body[% bodyabout %] class="[% page_type %]_page">
<div class="skip"><a href="#content" tabindex="0">[% lang('skip_to_content') %]</a></div>
Expand Down

0 comments on commit 33bed39

Please sign in to comment.