Asciidoctor:如何使用 asciidoctor-maven-plugin 添加 Google 分析代码到所有 HTML 页面
Asciidoctor: How to add Google Analytics code to all HTML pages with asciidoctor-maven-plugin
如何向 Asciidoctor 生成的所有 HTML 页面添加 Google 分析(或 Google 标签管理器)代码?有 an extension,但 Maven 存储库中没有。我正在使用 asciidoctor-maven-plugin
.
如果扩展发布于 RubyGems, you can download the dependency with the TorqueBox RubyGems Maven Proxy Repository。
查看 asciidoctor maven 示例中的 asciidoctor-pdf-with-theme-example。
如果您的文件 index.adoc
在同一目录中,则创建文件 index-docinfo-footer.html
并在该 adoc 文件中添加 :docinfo:
。
用以下内容填充页脚文件:
<script type="text/javascript">
dataLayer = [{'channel' : '{html-googleTagManagerChannel}', 'additional_tracking_code' : '{html-googleAnalyticsId}'}];
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{html-googleTagManagerId}');</script>
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={html-googleTagManagerId}" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
然后在 pom.xml:
中做类似的事情
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<configuration>
<attributes>
<html-googleAnalyticsId>UA-123456789-1</html-googleAnalyticsId>
<html-googleTagManagerId>GTM-ABCDE</html-googleTagManagerId>
<html-googleTagManagerChannel>MyProject</html-googleTagManagerChannel>
</attributes>
</configuration>
如何向 Asciidoctor 生成的所有 HTML 页面添加 Google 分析(或 Google 标签管理器)代码?有 an extension,但 Maven 存储库中没有。我正在使用 asciidoctor-maven-plugin
.
如果扩展发布于 RubyGems, you can download the dependency with the TorqueBox RubyGems Maven Proxy Repository。
查看 asciidoctor maven 示例中的 asciidoctor-pdf-with-theme-example。
如果您的文件 index.adoc
在同一目录中,则创建文件 index-docinfo-footer.html
并在该 adoc 文件中添加 :docinfo:
。
用以下内容填充页脚文件:
<script type="text/javascript">
dataLayer = [{'channel' : '{html-googleTagManagerChannel}', 'additional_tracking_code' : '{html-googleAnalyticsId}'}];
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{html-googleTagManagerId}');</script>
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={html-googleTagManagerId}" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
然后在 pom.xml:
中做类似的事情 <plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<configuration>
<attributes>
<html-googleAnalyticsId>UA-123456789-1</html-googleAnalyticsId>
<html-googleTagManagerId>GTM-ABCDE</html-googleTagManagerId>
<html-googleTagManagerChannel>MyProject</html-googleTagManagerChannel>
</attributes>
</configuration>