Skip to content

Commit a46be4a

Browse files
committed
Merge branch 'master' of github.com:snowplow/referer-parser
2 parents 9ebd9b8 + 95bfbd1 commit a46be4a

File tree

82 files changed

+48079
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+48079
-538
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/vendor/
2+
/composer.lock
3+
php/.idea
4+
ruby/.idea/.name
5+
ruby/.idea/.rakeTasks
6+
ruby/.idea/encodings.xml
7+
ruby/.idea/misc.xml
8+
ruby/.idea/modules.xml
9+
ruby/.idea/ruby.iml
10+
ruby/.idea/scopes/scope_settings.xml
11+
ruby/.idea/vcs.xml
12+
ruby/.idea/workspace.xml

README.md

+126-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Java/Scala: [![Build Status](https://travis-ci.org/snowplow/referer-parser.png)]
44

55
referer-parser is a multi-language library for extracting marketing attribution data (such as search terms) from referer URLs, inspired by the [ua-parser] [ua-parser] project (an equivalent library for user agent parsing).
66

7-
referer-parser is a core component of [Snowplow] [snowplow], the open-source web-scale analytics platform powered by Hadoop, Hive and Redshift.
7+
referer-parser is a core component of [Snowplow] [snowplow], the open-source web-scale analytics platform powered by Hadoop and Redshift.
88

99
_Note that we always use the original HTTP misspelling of 'referer' (and thus 'referal') in this project - never 'referrer'._
1010

@@ -13,7 +13,10 @@ _Note that we always use the original HTTP misspelling of 'referer' (and thus 'r
1313
* Ruby: [Snowplow Analytics] [snowplow-analytics]
1414
* Java/Scala: [Snowplow Analytics] [snowplow-analytics]
1515
* Python: [Don Spaulding] [donspaulding]
16-
* .NET: [Sepp Wijnands] [swijnands] at [iPerform Software] [iperform]
16+
* node.js (JavaScript): [Martin Katrenik] [mkatrenik]
17+
* .NET (C#): [Sepp Wijnands] [swijnands] at [iPerform Software] [iperform]
18+
* PHP: [Lars Strojny] [lstrojny]
19+
* Go: [Thomas Sileo] [tsileo]
1720
* `referers.yml`: [Snowplow Analytics] [snowplow-analytics]
1821

1922
## Usage: Java
@@ -58,6 +61,28 @@ for (r <- Parser.parse(refererUrl, pageUrl)) {
5861
}
5962
```
6063

64+
You can also provide a list of domains which should be considered internal:
65+
66+
```scala
67+
val refererUrl = "http://www.subdomain1.snowplowanalytics.com"
68+
val pageUrl = "http://www.snowplowanalytics.com"
69+
val internalDomains = List(
70+
"www.subdomain1.snowplowanalytics.com", "www.subdomain2.snowplowanalytics.com"
71+
)
72+
73+
import com.snowplowanalytics.refererparser.scala.Parser
74+
75+
for (r <- Parser.parse(refererUrl, pageUrl, internalDomains)) {
76+
println(r.medium) // => "internal"
77+
for (s <- r.source) {
78+
println(s) // => null
79+
}
80+
for (t <- r.term) {
81+
println(t) // => null
82+
}
83+
}
84+
```
85+
6186
For more information, please see the Java/Scala [README] [java-scala-readme].
6287

6388
## Usage: Ruby
@@ -116,6 +141,35 @@ r = Referer(referer_url, curr_url)
116141

117142
For more information, please see the Python [README] [python-readme].
118143

144+
## Usage: node.js
145+
146+
The node.js (JavaScript) version of this library uses a hybrid of the new and old API, and identifies search, social, webmail, internal and unknown referers:
147+
148+
Create a new instance of a Referer object by passing in the url you want to parse:
149+
150+
```js
151+
var Referer = require('referer-parser')
152+
153+
referer_url = 'http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari'
154+
155+
var r = new Referer(referer_url)
156+
```
157+
158+
The `r` variable now holds a Referer instance.
159+
160+
Optionally, pass in the current URL as well, to handle internal referers
161+
162+
```js
163+
var Referer = require('referer-parser')
164+
165+
var referer_url = 'http://www.snowplowanalytics.com/about/team'
166+
var current_url = 'http://www.snowplowanalytics.com/account/profile'
167+
168+
var r = Referer(referer_url, current_url)
169+
```
170+
171+
For more information, please see the node.js [README] [nodejs-readme].
172+
119173
## Usage: .NET
120174

121175
The .NET (C#) version of this library uses the updated API, and identifies search, social, webmail, internal and unknown referers:
@@ -137,6 +191,57 @@ Console.WriteLine(r.Term); // => "gateway oracle cards denise linn"
137191

138192
For more information, please see the .NET [README] [dotnet-readme].
139193

194+
## Usage: PHP
195+
196+
The PHP version of this library uses the updated API, and identifies search, social, webmail, internal and unknown referers:
197+
198+
```php
199+
use Snowplow\RefererParser\Parser;
200+
201+
$parser = new Parser();
202+
$referer = $parser->parse(
203+
'http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari',
204+
'http:/www.psychicbazaar.com/shop'
205+
);
206+
207+
if ($referer->isKnown()) {
208+
echo $referer->getMedium(); // "Search"
209+
echo $referer->getSource(); // "Google"
210+
echo $referer->getTerm(); // "gateway oracle cards denise linn"
211+
}
212+
```
213+
214+
For more information, please see the PHP [README] [php-readme].
215+
216+
## Usage: Go
217+
218+
The Go version of this library uses the updated API:
219+
220+
```go
221+
package main
222+
223+
import (
224+
"log"
225+
226+
"github.com/tsileo/referer-parser/go"
227+
)
228+
229+
func main() {
230+
referer_url := "http://www.google.com/search?q=gateway+oracle+cards+denise+linn&hl=en&client=safari"
231+
r := refererparser.Parse(referer_url)
232+
233+
log.Printf("Known:%v", r.Known)
234+
log.Printf("Referer:%v", r.Referer)
235+
log.Printf("Medium:%v", r.Medium)
236+
log.Printf("Search parameter:%v", r.SearchParameter)
237+
log.Printf("Search term:%v", r.SearchTerm)
238+
log.Printf("Host:%v", r.URI)
239+
}
240+
241+
```
242+
243+
For more information, please see the Go [README] [go-readme]
244+
140245
## referers.yml
141246

142247
referer-parser identifies whether a URL is a known referer or not by checking it against the [`referers.yml`] [referers-yml] file; the intention is that this YAML file is reusable as-is by every language-specific implementation of referer-parser.
@@ -168,7 +273,7 @@ The number of referers and the domains they use is constantly growing - we need
168273
We welcome contributions to referer-parser:
169274

170275
1. **New search engines and other referers** - if you notice a search engine, social network or other site missing from `referers.yml`, please fork the repo, add the missing entry and submit a pull request
171-
2. **Ports of referer-parser to other languages** - we welcome ports of referer-parser to new programming languages (e.g. JavaScript, PHP, Go, Haskell)
276+
2. **Ports of referer-parser to other languages** - we welcome ports of referer-parser to new programming languages (e.g. Lua, Go, Haskell, C)
172277
3. **Bug fixes, feature requests etc** - much appreciated!
173278

174279
**Please sign the [Snowplow CLA] [cla] before making pull requests.**
@@ -183,21 +288,30 @@ You can contact the Snowplow Analytics team through any of the [channels listed
183288

184289
`referers.yml` is based on [Piwik's] [piwik] [`SearchEngines.php`] [piwik-search-engines] and [`Socials.php`] [piwik-socials], copyright 2012 Matthieu Aubry and available under the [GNU General Public License v3] [gpl-license].
185290

186-
The original Ruby code is copyright 2012-2013 Snowplow Analytics Ltd and is available under the [Apache License, Version 2.0] [apache-license].
291+
The original Ruby code is copyright 2012-2014 Snowplow Analytics Ltd and is available under the [Apache License, Version 2.0] [apache-license].
292+
293+
The Java/Scala port is copyright 2012-2014 Snowplow Analytics Ltd and is available under the [Apache License, Version 2.0] [apache-license].
294+
295+
The Python port is copyright 2012-2014 [Don Spaulding] [donspaulding] and is available under the [Apache License, Version 2.0] [apache-license].
296+
297+
The node.js (JavaScript) port is copyright 2013-2014 [Martin Katrenik] [mkatrenik] and is available under the [Apache License, Version 2.0] [apache-license].
187298

188-
The Java/Scala port is copyright 2012-2013 Snowplow Analytics Ltd and is available under the [Apache License, Version 2.0] [apache-license].
299+
The .NET (C#) port is copyright 2013-2014 [iPerform Software] [iperform] and is available under the [Apache License, Version 2.0] [apache-license].
189300

190-
The Python port is copyright 2012-2013 [Don Spaulding] [donspaulding] and is available under the [Apache License, Version 2.0] [apache-license].
301+
The PHP port is copyright 2013-2014 [Lars Strojny] [tsileo] and is available under the [MIT License] [mit-license].
191302

192-
The .NET port is copyright 2013 [iPerform Software] [iperform] and is available under the [Apache License, Version 2.0] [apache-license].
303+
The Go port is copyright 2014 [Thomas Sileo] [lstrojny] and is available under the [MIT License] [mit-license].
193304

194305
[ua-parser]: https://github.com/tobie/ua-parser
195306

196307
[snowplow]: https://github.com/snowplow/snowplow
197308
[snowplow-analytics]: http://snowplowanalytics.com
198309
[donspaulding]: https://github.com/donspaulding
199310
[swijnands]: https://github.com/swijnands
311+
[mkatrenik]: https://github.com/mkatrenik
200312
[iperform]: http://www.iperform.nl/
313+
[lstrojny]: https://github.com/lstrojny
314+
[tsileo]: https://github.com/tsileo
201315

202316
[piwik]: http://piwik.org
203317
[piwik-search-engines]: https://github.com/piwik/piwik/blob/master/core/DataFiles/SearchEngines.php
@@ -206,11 +320,15 @@ The .NET port is copyright 2013 [iPerform Software] [iperform] and is available
206320
[ruby-readme]: https://github.com/snowplow/referer-parser/blob/master/ruby/README.md
207321
[java-scala-readme]: https://github.com/snowplow/referer-parser/blob/master/java-scala/README.md
208322
[python-readme]: https://github.com/snowplow/referer-parser/blob/master/python/README.md
323+
[nodejs-readme]: https://github.com/snowplow/referer-parser/blob/master/nodejs/README.md
209324
[dotnet-readme]: https://github.com/snowplow/referer-parser/blob/master/dotnet/README.md
210-
[referers-yml]: https://github.com/snowplow/referer-parser/blob/master/referers.yml
325+
[php-readme]: https://github.com/snowplow/referer-parser/blob/master/php/README.md
326+
[go-readme]: https://github.com/snowplow/referer-parser/blob/master/go/README.md
327+
[referers-yml]: https://github.com/snowplow/referer-parser/blob/master/resources/referers.yml
211328

212329
[talk-to-us]: https://github.com/snowplow/snowplow/wiki/Talk-to-us
213330

214331
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
215332
[gpl-license]: http://www.gnu.org/licenses/gpl-3.0.html
333+
[mit-license]: http://opensource.org/licenses/MIT
216334
[cla]: https://github.com/snowplow/snowplow/wiki/CLA

composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "snowplow/referer-parser",
3+
"description": "Snowplow Refer(r)er parser for PHP",
4+
"require-dev": {
5+
"phpunit/phpunit": "3.*",
6+
"symfony/yaml": "*"
7+
},
8+
"suggest": {
9+
"symfony/yaml": "Support for YAML configuration file"
10+
},
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Lars Strojny",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"autoload": {
19+
"psr-0": {
20+
"Snowplow\\RefererParser": "php/src/"
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)