Skip to content
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

CLDR-16389 v43 update analytics tags #2795

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions tools/cldr-code/src/main/java/org/unicode/cldr/tool/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,27 @@ public void writeContents(Writer pw, Factory factory) throws IOException {
throw new IllegalArgumentException("Not implemented yet");
}

public void writeFooter(FormattedFileWriter pw) throws IOException {
standardFooter(pw, AnalyticsID.CLDR);
private static final class AnalyticsHelper {
private static final AnalyticsHelper INSTANCE = new AnalyticsHelper();

public final String str;

AnalyticsHelper() {
str = ToolUtilities.getUTF8Data("analytics.html").lines().collect(Collectors.joining("\n"));
}
}

private enum AnalyticsID {
CLDR("UA-7672775-1"), ICU("UA-7670213-1"), ICU_GUIDE("UA-7670256-1"), UNICODE("UA-7670213-1"), UNICODE_UTILITY("UA-8314904-1");
public enum AnalyticsID {
CLDR("G-BPN1D3SEJM"), ICU("G-06PL1DM20S"), ICU_GUIDE("UA-7670256-1"), UNICODE("G-GC4HXC4GVQ"), UNICODE_UTILITY("G-0M7Q5QLZPV");
Comment on lines +146 to +147
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know why the other tags are here, but i updated them

public final String id;

private AnalyticsID(String id) {
this.id = id;
}
}

private static void standardFooter(FormattedFileWriter pw, AnalyticsID analytics) throws IOException {
pw.write("<div style='text-align: center; margin-top:2em; margin-bottom: 60em;'><br>\n"
+ "<a href='https://www.unicode.org/copyright.html'>\n"
+ "<img src='https://www.unicode.org/img/hb_notice.gif' style='border-style: none; width: 216px; height:50px;' alt='Access to Copyright and terms of use'>"
+ "</a>\n"
+ "</div><script>\n\n"
+ "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){"
+ "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),"
+ "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)"
+ "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');"
+ " ga('create', '"
+ analytics
+ "', 'auto');"
+ " ga('send', 'pageview');"
+ "</script>\n");
public String getScript() {
return AnalyticsHelper.INSTANCE.str.replaceAll("TAG_ID", id);
}
}

public final void writeChart(Anchors anchors) {
Expand All @@ -169,7 +162,6 @@ public final void writeChart(Anchors anchors) {
x.setDirectory(getDirectory());
x.setShowDate(getShowDate());
writeContents(x);
writeFooter(x);
} catch (IOException e) {
throw new ICUUncheckedIOException(e);
}
Expand All @@ -190,7 +182,7 @@ public String getFixLinkFromPath(CLDRFile cldrFile, String path) {

/**
* Attempt to allocate the Chart that goes along with this report
* Also see {@link org.unicode.cldr.util.VoterReportStatus.ReportId}
* Also see {@link org.unicode.cldr.util.VoterReportStatus.ReportId}
* and keep up to date
*/
public static Chart forReport(final ReportId report, final String locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public void close() {
"%title%", title,
"%index%", indexLink,
"%index-title%", indexTitle,
"%body%", contents };
"%body%", contents,
"%analytics%", Chart.AnalyticsID.CLDR.getScript() };
writeTargetWithReplacements(dir, targetFileName, templateFileName, replacements);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void close() throws IOException {
out.write("</div>");
PrintWriter pw2 = org.unicode.cldr.draft.FileUtilities.openUTF8Writer(dir, filename);
String[] replacements = { "%header%", "", "%title%", title, "%version%", ToolConstants.CHART_DISPLAY_VERSION,
"%date%", CldrUtility.isoFormatDateOnly(new Date()), "%body%", out.toString() };
"%date%", CldrUtility.isoFormatDateOnly(new Date()), "%body%", out.toString(), "%analytics%", Chart.AnalyticsID.CLDR.getScript() };
final String templateFileName = "chart-template.html";
FileUtilities.appendBufferedReader(ToolUtilities.getUTF8Data(templateFileName), pw2, replacements);
pw2.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ static public void getChartTemplate(String title, String version,
.add("%index%", "index.html")
.add("%header%", header)
.add("%version%", version)
.add("%analytics%", Chart.AnalyticsID.CLDR.getScript())
.add("%date%", showDate ? CldrUtility.isoFormatDateOnly(new Date()) : "");
if (indexTitle != null) {
langTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.regex.Pattern;

import org.unicode.cldr.draft.FileUtilities;
import org.unicode.cldr.tool.Chart;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -176,15 +177,7 @@ public static String getPath(String path) {
return getPath(path, null);
}

public static final String ANALYTICS = "<script>\n"
+ "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n"
+ "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n"
+ "</script>\n"
+ "<script>\n"
+ "try {\n"
+ "var pageTracker = _gat._getTracker(\"UA-7672775-1\");\n"
+ "pageTracker._trackPageview();\n"
+ "} catch(err) {}</script>";
public static final String ANALYTICS = Chart.AnalyticsID.CLDR.getScript();

public static final List<String> MINIMUM_LANGUAGES = Arrays.asList(new String[] { "ar", "en", "de", "fr", "hi",
"it", "es", "pt", "ru", "zh", "ja" }); // plus language itself
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'TAG_ID');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>

<head>
%analytics%
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>%title%</title>
<link rel="stylesheet" type="text/css"
Expand Down Expand Up @@ -44,7 +45,7 @@
<tr><td style="text-align: center" colSpan="3"><a class="upLink" href="%index%">%index-title%</a></td></tr>
</table>
</div>
<!--
<!--
<div align="center">
<table style="margin: 1em">
<tr>
Expand All @@ -56,22 +57,16 @@
</table>
</div>
-->
%body%
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-7672775-1', 'auto');
ga('send', 'pageview');
</script>
<!-- begin main body-->
%body%
<!-- end main body -->
</div>
<div style='text-align: center; margin-top:2em; margin-bottom: 60em;'><br>
<a href='https://www.unicode.org/copyright.html'>
<img src='https://www.unicode.org/img/hb_notice.gif' style='border-style: none; width: 216px; height:50px;'
alt='Access to Copyright and terms of use'>
</a>
</div>
</body>

</html>
</body>
</html>