我以使用FileLibrary的方式实现。
然后我有以下代码:
updateRoot:anHtmlRoot
super updateRoot: anHtmlRoot.
anHtmlRoot title: self title.
anHtmlRoot link beShortcutIcon; url: MyfileLibrary / #myGraphicPng.
anHtmlRoot javascript url: (MyFileLibrary urlOf: #analyticsJs)
谷歌检查页面确定,但从来没有我得到实数,总是处于“等待数据”的状态。
任何提示或示例都将受到赞赏。
答案 0 :(得分:3)
Google Analytics适用于Seaside。多年来我一直在许多(主要是基于码头的)海边站点使用它。
确保#analyticsJs
包含正确的Google Analytics跟踪代码。将代码内嵌到脚本标记中效率更高(并由Google建议),但我认为它也可以使用URL。
确保您的应用程序在完全限定的域名(FQDN)上运行。我假设跟踪器无法在localhost
上运行,请参阅Google Analytics Help以获取更多信息。
答案 1 :(得分:3)
这是一个稍微复杂(逐字)的示例,支持多个跟踪器(例如,CC跟踪数据到客户端的帐户),自定义变量和URL生成:
updateRoot:root
super updateRoot: root.
root javascript with: (String streamContents: [:ws | self renderAnalyticsOn: ws]).
renderAnalyticsOn:stream
| options |
options := OrderedCollection new.
self trackingConfiguration keysAndValuesDo:
[:tracker :accountid |
| isForClient |
isForClient := tracker notEmpty.
options add: (Array with: tracker , '_setAccount' with: accountid).
isForClient
ifTrue:
[options
add: (Array with: tracker , '_setDomainName' with: 'none');
add: (Array with: tracker , '_setAllowLinker' with: true);
add: (Array with: tracker , '_setAllowHash' with: false)].
self trackingCustomVariables do:
[:array |
array at: 1 put: tracker , array first.
options add: array].
options add: (Array with: tracker , '_trackPageview' with: '/' , self trackingURL)].
stream
nextPutAll: 'var _gaq = _gaq || [];';
nextPutAll: '_gaq.push('.
options do: [:ea | stream json: ea] separatedBy: [stream nextPut: $,].
stream nextPutAll: ');'.
stream
nextPutAll: '(function() {';
nextPutAll: 'var ga = document.createElement(''script''); ga.type = ''text/javascript''; ga.async = true;';
nextPutAll: 'ga.src = (''https:'' == document.location.protocol ? ''https://ssl'' : ''http://www'') + ''.google-analytics.com/ga.js'';';
nextPutAll: 'var s = document.getElementsByTagName(''script'')[0]; s.parentNode.insertBefore(ga, s);';
nextPutAll: '})();'.
trackingConfiguration
| trackers |
trackers := (Dictionary new)
at: '' put: 'UA-XXXX-YY';
yourself.
self session googleAnalytics ifNotNil: [:v | trackers at: 'b.' put: v].
^trackers.
trackingCustomVariables
^Array with: (Array
with: '_setCustomVar'
with: 1
with: 'Application'
with: self class applicationName
with: 2).
trackingURL
^String streamContents: [:ws | crumbs do: [:ea | ws nextPutAll: ea title asAnalyticsURL] separatedBy: [ws nextPut: $/]].
asAnalyticsURL
^self asLowercase copyReplace: Character space with: $_