channel_grouping 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/channel_grouping.gemspec +28 -0
- data/lib/channel_grouping.rb +30 -0
- data/lib/channel_grouping/destination.rb +33 -0
- data/lib/channel_grouping/source.rb +61 -0
- data/lib/channel_grouping/version.rb +3 -0
- data/sources.yml +81 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfc61bdc6bab522983f1384b9aebb1e55a962263
|
4
|
+
data.tar.gz: 42b384bd369ac19d86fbd788d995523a22ee6af2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52d7742086e84d0bddf29a8a24bb2ad4e58b9dda298ac7418de4d7479b8cc55dfbbba6efcd4b7cd858a3ed1443acab5262718666e07015710b5402364332dddb
|
7
|
+
data.tar.gz: 1624528705e87a59221c94864536aa332e41b431d8b31a6e82b6cb9751c4affc7ef97e52746941a4ec3a5c843bd168b9653a173c8900994c65b262f3715048f0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# ChannelGrouping
|
2
|
+
|
3
|
+
Groups traffic into channels, similar to the groupings in Google Analytics
|
4
|
+
|
5
|
+
Given a source_url and destination_url, this gem will determine the traffic's channel
|
6
|
+
(eg Social, Direct, Organic Search, Paid Search).
|
7
|
+
|
8
|
+
The categorizations are based on Google Analytics' [default channel definitions](https://support.google.com/analytics/answer/3297892)
|
9
|
+
|
10
|
+
|
11
|
+
## Limitations
|
12
|
+
|
13
|
+
1. Display and Paid Search groupings do not take into account the Ad Distribution Network
|
14
|
+
2. The list of Social Networks and Search Engines may differ from Google's lists.
|
15
|
+
- See `sources.yml` and https://support.google.com/analytics/answer/2795821
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```Ruby
|
20
|
+
ChannelGrouping.identify(source_url: 'https://www.google.com?s=some-query', destination_url: 'https://your-site.com')
|
21
|
+
#=> 'Organic Search'
|
22
|
+
```
|
23
|
+
|
24
|
+
```Ruby
|
25
|
+
ChannelGrouping.identify(source_url: 'https://www.some-site.com', destination_url: 'https://your-site.com?utm_medium=cpc')
|
26
|
+
#=> 'Paid Search'
|
27
|
+
```
|
28
|
+
|
29
|
+
```Ruby
|
30
|
+
ChannelGrouping.identify(source_url: nil, destination_url: 'https://your-site.com')
|
31
|
+
#=> 'Direct'
|
32
|
+
```
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'channel_grouping'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install channel_grouping
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/[my-github-username]/channel_grouping/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "channel_grouping"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'channel_grouping/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "channel_grouping"
|
8
|
+
spec.version = ChannelGrouping::VERSION
|
9
|
+
spec.authors = ["Ian Yamey"]
|
10
|
+
spec.email = ["ian@policygenius.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Groups traffic into channels, similar to the groupings in Google Analytics'
|
13
|
+
spec.description = "Given a source_url and destination_url, this gem will determine the traffic's " \
|
14
|
+
"channel (eg Social, Direct, Organic Search, Paid Search). The categorization is " \
|
15
|
+
"based on Google Analytics' default channel definitions (see https://support.google.com/analytics/answer/3297892)"
|
16
|
+
spec.homepage = 'https://github.com/ianyamey/channel_grouping'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "rack"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'channel_grouping/version'
|
2
|
+
require 'channel_grouping/source'
|
3
|
+
require 'channel_grouping/destination'
|
4
|
+
|
5
|
+
module ChannelGrouping
|
6
|
+
def self.identify(source_url: , destination_url:)
|
7
|
+
destination = Destination.new(destination_url)
|
8
|
+
|
9
|
+
medium = destination.medium
|
10
|
+
|
11
|
+
return 'Email' if medium =~ /^email$/i
|
12
|
+
return 'Affiliates' if medium =~ /^affiliate$/i
|
13
|
+
return 'Referral' if medium =~ /^referral$/i
|
14
|
+
return 'Organic Search' if medium =~ /^organic$/i
|
15
|
+
return 'Paid Search' if medium =~ /^(cpc|ppc|paidsearch)$/i
|
16
|
+
return 'Other Advertising' if medium =~ /^(cpv|cpa|cpp)$/i
|
17
|
+
return 'Display' if medium =~ /^(display|cpm|banner)$/i
|
18
|
+
return 'Social' if medium =~ /^(social|social-network|social-media|sm|social network|social media)$/i
|
19
|
+
|
20
|
+
source = Source.new(source_url)
|
21
|
+
|
22
|
+
return 'Organic Search' if source.search_engine?
|
23
|
+
return 'Social' if source.social_network?
|
24
|
+
return 'Direct' if source.direct? && (medium == 'none' || medium.nil?)
|
25
|
+
return 'Direct' if source.host == destination.host
|
26
|
+
return 'Referral' if source.host && (medium == 'none' || medium.nil?)
|
27
|
+
|
28
|
+
'Other'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rack/utils'
|
3
|
+
|
4
|
+
module ChannelGrouping
|
5
|
+
class Destination
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize(url)
|
9
|
+
@url = url
|
10
|
+
end
|
11
|
+
|
12
|
+
def medium
|
13
|
+
m = params['utm_medium']
|
14
|
+
m == '' ? nil : m
|
15
|
+
end
|
16
|
+
|
17
|
+
def host
|
18
|
+
uri.host
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def uri
|
24
|
+
@uri ||= URI(url.to_s)
|
25
|
+
rescue URI::InvalidURIError
|
26
|
+
URI('')
|
27
|
+
end
|
28
|
+
|
29
|
+
def params
|
30
|
+
Rack::Utils.parse_nested_query(uri.query)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module ChannelGrouping
|
7
|
+
class Source
|
8
|
+
CONFIG_FILENAME = 'sources.yml'
|
9
|
+
|
10
|
+
attr_reader :url
|
11
|
+
|
12
|
+
def initialize(url)
|
13
|
+
@url = url
|
14
|
+
end
|
15
|
+
|
16
|
+
def search_engine?
|
17
|
+
self.class.search_engines.any? do |search_engine_host|
|
18
|
+
host_matches?(search_engine_host)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def social_network?
|
23
|
+
self.class.social_networks.any? do |social_network_host|
|
24
|
+
host_matches?(social_network_host)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def direct?
|
29
|
+
uri.host.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def host
|
33
|
+
uri.host
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.social_networks
|
37
|
+
@social_networks ||= config['social_networks']
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.search_engines
|
41
|
+
@search_engines ||= config['search_engines']
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.config
|
45
|
+
root = Pathname.new(File.expand_path("../../..", __FILE__))
|
46
|
+
YAML.load_file(root.join(CONFIG_FILENAME))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def host_matches?(other_host)
|
52
|
+
host =~ Regexp.new(other_host)
|
53
|
+
end
|
54
|
+
|
55
|
+
def uri
|
56
|
+
@uri ||= URI(url.to_s)
|
57
|
+
rescue URI::InvalidURIError
|
58
|
+
URI('')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/sources.yml
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
social_networks:
|
2
|
+
- 'facebook\.com'
|
3
|
+
- 'reddit\.com'
|
4
|
+
- 't\.co'
|
5
|
+
- 'twitter\.com'
|
6
|
+
- 'wordpres\.com'
|
7
|
+
- 'disqus\.com'
|
8
|
+
- 'linkedin\.com'
|
9
|
+
- 'lnkd\.in'
|
10
|
+
- 'blogspot'
|
11
|
+
- 'stumbleupon\.com'
|
12
|
+
- 'tumblr\.com'
|
13
|
+
- 'getpocket\.com'
|
14
|
+
- 'glassdoor\.com'
|
15
|
+
- 'meetup\.com'
|
16
|
+
- 'pinterest\.com'
|
17
|
+
- 'plus\.url\.google\.com'
|
18
|
+
- 'youtube\.com'
|
19
|
+
- 'yammer\.com'
|
20
|
+
- 'plus\.google\.com'
|
21
|
+
- 'touch\.www'
|
22
|
+
- 'diigo\.com'
|
23
|
+
- 'news\.ycombinator\.com'
|
24
|
+
- 'paper\.li'
|
25
|
+
- 'digg\.com'
|
26
|
+
- 'bigtent\.com'
|
27
|
+
- 'blogger\.com'
|
28
|
+
- 'googleplus'
|
29
|
+
- 'groups\.google\.com'
|
30
|
+
- 'hootsuite\.com'
|
31
|
+
- 'instagram\.com'
|
32
|
+
- 'instapaper\.com'
|
33
|
+
- 'netvibes\.com'
|
34
|
+
- 'ow\.ly'
|
35
|
+
- 'pinboard\.in'
|
36
|
+
- 'quora\.com'
|
37
|
+
- 'scoop\.it'
|
38
|
+
- 'slashdot\.org'
|
39
|
+
- 'tinyurl\.com'
|
40
|
+
- 'twitter'
|
41
|
+
- 'uk\.pinterest\.com'
|
42
|
+
- 'wikihow\.com'
|
43
|
+
search_engines:
|
44
|
+
- 'daum\.net'
|
45
|
+
- 'eniro\.se'
|
46
|
+
- 'naver\.com'
|
47
|
+
- 'google\.'
|
48
|
+
- 'yahoo\.com'
|
49
|
+
- 'msn\.com'
|
50
|
+
- 'bing\.'
|
51
|
+
- 'aol\.com'
|
52
|
+
- 'lycos\.com'
|
53
|
+
- 'ask\.com'
|
54
|
+
- 'altavista\.com'
|
55
|
+
- 'search\.netscape\.com'
|
56
|
+
- 'about\.com'
|
57
|
+
- 'mamma\.com'
|
58
|
+
- 'alltheweb\.com'
|
59
|
+
- 'voila\.fr'
|
60
|
+
- 'search\.virgilio\.it'
|
61
|
+
- 'baidu\.com'
|
62
|
+
- 'alice\.com'
|
63
|
+
- 'yandex\.com'
|
64
|
+
- 'najdi\.org\.mk'
|
65
|
+
- 'aol\.com'
|
66
|
+
- 'mamma\.com'
|
67
|
+
- 'seznam\.cz'
|
68
|
+
- 'search\.com'
|
69
|
+
- 'wp\.pl'
|
70
|
+
- 'online\.onetcenter\.org'
|
71
|
+
- 'szukacz\.pl'
|
72
|
+
- 'yam\.com'
|
73
|
+
- 'pchome\.com'
|
74
|
+
- 'kvasir\.no'
|
75
|
+
- 'sesam\.no'
|
76
|
+
- 'ozu\.es'
|
77
|
+
- 'terra\.com'
|
78
|
+
- 'mynet\.com'
|
79
|
+
- 'ekolay\.net'
|
80
|
+
- 'rambler\.ru'
|
81
|
+
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: channel_grouping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Yamey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Given a source_url and destination_url, this gem will determine the traffic's
|
84
|
+
channel (eg Social, Direct, Organic Search, Paid Search). The categorization is
|
85
|
+
based on Google Analytics' default channel definitions (see https://support.google.com/analytics/answer/3297892)
|
86
|
+
email:
|
87
|
+
- ian@policygenius.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- channel_grouping.gemspec
|
101
|
+
- lib/channel_grouping.rb
|
102
|
+
- lib/channel_grouping/destination.rb
|
103
|
+
- lib/channel_grouping/source.rb
|
104
|
+
- lib/channel_grouping/version.rb
|
105
|
+
- sources.yml
|
106
|
+
homepage: https://github.com/ianyamey/channel_grouping
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.4.6
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Groups traffic into channels, similar to the groupings in Google Analytics
|
130
|
+
test_files: []
|