Comments (8)
Does this work? I have no way to test it.
class @GoogleAnalytics
@load: ->
# Create a script element and insert it in the DOM
ua = document.createElement("script")
ua.type = "text/javascript"
ua.async = true
ua.src = ((if "https:" is document.location.protocol then "https://ssl" else "http://www")) + ".google-analytics.com/analytics.js"
firstScript = document.getElementsByTagName("script")[0]
firstScript.parentNode.insertBefore ua, firstScript
# Set account
ga 'create', GoogleAnalytics.analyticsId(), 'auto'
# If Turbolinks is supported, set up a callback to track pageviews on page:change.
# If it isn't supported, just track the pageview now.
if typeof Turbolinks isnt 'undefined' and Turbolinks.supported
document.addEventListener "page:change", (->
GoogleAnalytics.trackPageview()
), true
else
GoogleAnalytics.trackPageview()
@trackPageview: (url) ->
unless GoogleAnalytics.isLocalRequest()
if url
ga.send 'pageview', url
else
ga.send 'pageview'
@isLocalRequest: ->
GoogleAnalytics.documentDomainIncludes "local"
@documentDomainIncludes: (str) ->
document.domain.indexOf(str) isnt -1
@analyticsId: ->
# your google analytics ID(s) here...
GoogleAnalytics.load()
from turbolinks-compatibility.
Here is our solution for Google Universal Analytics. Pretty straight forward and it works for us. Pull request if you'd like to merge - #46.
I would recommend renaming Google Analytics
to Google Classic Analytics
or something more descriptive as is being deprecated by Google.
from turbolinks-compatibility.
Did you try my solution? I'm curious to know if it works.
from turbolinks-compatibility.
No, I haven't tried. I saw your solution last night just before pushing mine (I had it for a while, just didn't have time to create the page), as I did a final search for UA to see if there is already an issue.
Personally I'd prefer going with something that is very close with official implementation rather than a complete overhaul. For example, adding support for Display Advertising using your solution is not as trivial as just adding the code snippet as-is ga('require', 'displayfeatures');
from turbolinks-compatibility.
I haven't had a chance to try @rmarescu's PR yet but I'd like to see something of that nature added. It's nearly a drop in replacement which is always good.
Have you done extensive testing to make sure it's gathering all the hits it should be tracking?
from turbolinks-compatibility.
We've used the implementation suggested on a site that generated more than 400 million page views in November; we also have custom event tracking implemented
from turbolinks-compatibility.
@rmarescu Awesome. I imagine you guys have enhanced link attribution working too?
Ex.
<script>
ga('require', 'displayfeatures');
ga('require', 'linkid', 'linkid.js');
ga('set', 'location', location.href.split('#')[0]);
ga('send', 'pageview', { 'title': document.title });
</script>
from turbolinks-compatibility.
I wasn't asking if my solution works because I would use it instead of yours. If it works, I was going to include both so that users would have options.
Anyway, I merged your PR. Thanks for submitting it.
from turbolinks-compatibility.
Related Issues (20)
- Turbolinks not working with google ads or LiveHelpNow
- Google Tag Manager HOT 5
- Facebook like/share button still disappearing HOT 1
- Marketo munchkin tracker integration request
- Integration with Google TagManager HOT 4
- Happyfox Chat loading problem after language change HOT 4
- Can't find a way to change Facebook language HOT 1
- Loading Javascripts Problem HOT 1
- React Native HOT 1
- Turbolinks 5 compatibility HOT 8
- Should the solutions propose both coffee script and standart js version?
- Segment.com HOT 1
- Olark Hummingbird theme
- New Sharethis implementation and Turbolinks' incompatibility HOT 3
- owlCarousel not Loaded
- Zendesk old and new tab displayed HOT 2
- Turbolink 5 and Google DFP not working
- LiveZilla Compatability
- Using the Freshdesk/Freshdesk Widget with Turbolinks HOT 4
- SaleForce Widget with turbolinks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbolinks-compatibility.