-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Turbolinks #29
Comments
I feel like that is something that's better left to the app's specific requirements. What you could do, is still use the init tag, but pass Then using the coffeescript in your ticket, you can run the ga commands. Would just need to make sure that turbolinks doesn't reload the GA scripts, which I believe you can do by placing the init tag in the head |
Think it needs to work with Turbo Links as that's standard for rails. |
To accomplish what you're looking for, here is a snippet of code that'll get you started. I welcome any PR that would like to include a JavaScript class for this style, but I still feel its best left to the application. application.html.erb<html>
<head>
<%= analytics_init(skip_pageview: true) %>
</head>
....
</html> Javascript in app(function() {
document.addEventListener("turbolinks:load", function() {
ga('send', 'pageview', window.location.pathname);
});
})(); Turbo Links will execute any javascripts you place in the body as the different pages load too, so there is always that option as well. <body>
<div>Hello world</div>
<%= GA::Events::TrackPageview.new %>
</body> *all untested |
We had to change the javascript part: (function() {
document.addEventListener("turbolinks:load", function() {
ga('send', 'pageview', window.location.pathname);
});
})(); |
Updated above snippet to use the pathname in the pageview event |
Do you have any plans to support Turbolinks? like described here:
http://reed.github.io/turbolinks-compatibility/google_analytics.html
The text was updated successfully, but these errors were encountered: