How to insert a Google Analytics script (new version) in a seaside application

I implemented a way to use FileLibrary.

Then I have 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 checks the page in order, but I never get real numbers, it is always in a "pending data" state.

Any hint or example will be appreciated.

+3
source share
2 answers

Google Analytics works well with Seaside. I have used it for many years on many (mostly on the pier) seaside sites.

  • , #analyticsJs Google Analytics. ( Google) script, , URL-.

  • , (FQDN). , localhost, . Google Analytics .

+3

() (, CC ), URL:

updateRoot: root

super updateRoot: root.
root javascript with: (String streamContents: [:ws | self renderAnalyticsOn: ws]).

renderAnalyticsOn:

| 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: $_
+3

Source: https://habr.com/ru/post/1785996/


All Articles