Alright, I managed to get it to work.
I'm not expert enough in Closure to understand why, but what made it work for
me was that the function was local-bound, i.e the following didn't work:
(def ga (aget js/window "ga"))
;; ... and later in the code
(ga "create" my-account-id "auto")
However, the following did work:
(defn ga [& args]
(let [g (aget js/window "ga")]
(apply g args)))
;; ... and later in the code
(ga "create" my-account-id "auto")
Le dimanche 7 juin 2015 14:47:43 UTC+2, Val Waeselynck a écrit :
> Le jeudi 17 juillet 2014 09:36:02 UTC+2, Thomas Heller a écrit :
> > Hey,
> >
> > the problem is not that closure munges the window.ga function, it is that
> > closure creates a var named ga which can be anything but is not the
> > analytics ga. At least it was in my case.
> >
> > My solution was to use the renaming feature of the analytics snippet to use
> > a name closure won't generate and then call it using aget.
> >
> > Example:
> >
> > Last part of the analytics snippet:
> > (window, document, 'script', '//www.google-analytics.com/analytics.js',
> > '$MY_GA');
> >
> > Then to call analytics:
> >
> > (let [ga (aget js/window "$MY_GA")]
> > (ga "create" analytics-account-id "auto"))
> >
> > That fixed everything for me.
> >
> > HTH,
> > /thomas
> >
> > On Thursday, July 17, 2014 6:33:28 AM UTC+2, tal giat wrote:
> > > Hi,
> > >
> > > We have clojurescript code calling the google analytics api that is
> > > created on a regular html page with the usual embed code, like this:
> > >
> > > (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');
> > >
> > > In a clojurescript file we have function to report pageviews like that:
> > >
> > > (defnk init-analytics [analytics-account-id user-id account-id]
> > > (.ga js/window "create" analytics-account-id "auto")
> > > (.ga js/window "set" "&uid" (str user-id))
> > > (.ga js/window "set" "dimension1" (str user-id))
> > > (.ga js/window "set" "dimension2" (str account-id))
> > > (.ga js/window "send" "pageview" (get-page)))
> > >
> > > This works fine without the advanced compilation mode but fails on
> > > advanced one. This code is being compiled to a munged name, in this case
> > > window.nc instead of window.ga
> > >
> > > I've tried to add to our extens file (we have other external libraries
> > > that work fine) the follwoing:
> > > var ga = function(args); but that doesn't help.
> > >
> > > The closure compiler has externs for the analytics api but that seems
> > > like an old one (old analytics API that is):
> > >
> > > https://github.com/google/closure-compiler/blob/master/contrib/externs/google_analytics_api.js
> > >
> > > Does someone ran into similar problem and can post a solution
> > >
> > > Thanks
>
> Didn't work for me :/
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.