I implemented at the way of use a FileLibrary.
Then I've the following code:
updateRoot: anHtmlRoot
开发者_如何学运维super updateRoot: anHtmlRoot.
anHtmlRoot title: self title.
anHtmlRoot link beShortcutIcon; url: MyfileLibrary / #myGraphicPng.
anHtmlRoot javascript url: (MyFileLibrary urlOf: #analyticsJs)
Google check the page ok, but never I get real numbers, allways is in the state of "awaiting data".
Any hint or example will be appreciated.
Google Analytics works well with Seaside. I've been using it for years on many (mostly Pier based) Seaside sites.
Make sure that
#analyticsJs
contains the correct Google Analytics tracking code. It is much more efficient (and suggested by Google) to inline the code into the script tag, but I assume it also works using an URL.Make sure that your application is running on a fully qualified domain name (FQDN). I assume that the tracker does not work on
localhost
, see Google Analytics Help for more information.
Here's a slightly more complicated (verbatim) example to support multiple trackers (to CC tracking data to client's account, for example), custom variables and URL generation:
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: $_
精彩评论