2

基本上,我是编程新手,被告知从 Clojure 和 Hoplon(使用 Clojurescript)开始。我正在尝试将 Google Analytics 代码翻译成 clojurescript,但我意识到我不知道该怎么做。有人可以翻译这段代码吗?如果可能的话,我也非常感谢解释如何自己解决这些问题。我很感激我能得到的任何帮助。(我已经搜索过,我发现的只是翻译的小片段,但从来没有完整的东西,所以我不知道如何实现它。)

<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', 'GOOGLE-ANALYTICS-ID', 'auto');
  ga('send', 'pageview');

</script>

再次感谢您的帮助。

4

1 回答 1

4

您不需要(甚至最好)移植该代码。以下是“learndatalogtoday”项目的片段粘贴示例:

https://github.com/jonase/learndatalogtoday/blob/master/src/clj/learndatalogtoday/views.clj

(def google-analytics-string
  "(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-40247950-2', 'learndatalogtoday.org');
  ga('send', 'pageview');")

后来:

  (html5
   [:head
    (include-css "/third-party/bootstrap/css/bootstrap.css")
    (include-css "/style.css")
    [:title "Learn Datalog Today!"]
    [:script google-analytics-string]]
于 2015-09-07T21:28:48.673 回答