Skip to content
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

Added other tracker URLs #8

Merged
merged 1 commit into from
Mar 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Readme.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ haml example:
```haml
= tracking_code(:account => 'UA-12345-6', :tracker_methods => tracker_methods)
```
### Other Tracking URLs

You can use other Tracking URLs with the option tracker_url and ssl_tracker_url.

erb example:

```erb
<%= tracking_code(:account => 'UA-12345-6', :tracker_url: 'stats.g.doubleclick.net/dc.js', ssl_tracker_url: 'stats.g.doubleclick.net/dc.js') %>
```

haml example:

```haml
= tracking_code(:account => 'UA-12345-6', :tracker_url: 'stats.g.doubleclick.net/dc.js', ssl_tracker_url: 'stats.g.doubleclick.net/dc.js')
```

## Development

Expand Down
13 changes: 9 additions & 4 deletions lib/split/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ module Analytics
def tracking_code(options={})
# needs more options: http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html
account = options.delete(:account)
tracker_url = options.delete(:tracker_url)
ssl_tracker_url = options.delete(:ssl_tracker_url)
tracker_methods = options.delete(:tracker_methods)


tracker_url = 'http://' + (tracker_url || 'www.google-analytics.com/ga.js')
ssl_tracker_url = 'https://' + (ssl_tracker_url || 'ssl.google-analytics.com/ga.js')

code = <<-EOF
<script type="text/javascript">
var _gaq = _gaq || [];
Expand All @@ -16,7 +21,7 @@ def tracking_code(options={})
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.src = ('https:' == document.location.protocol ? '#{ssl_tracker_url}' : '#{tracker_url}');
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Expand All @@ -33,9 +38,9 @@ def custom_variables
end
arr.reverse[0..4].reverse.join("\n")
end

private

def insert_tracker_methods(tracker_methods)
return nil if tracker_methods.nil?
arr = []
Expand Down