admob 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.txt +47 -11
- data/lib/admob.rb +66 -27
- metadata +5 -4
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -10,20 +10,52 @@ Enables easy integration of AdMob services (ads and/or analytics) into a RoR mob
|
|
10
10
|
|
11
11
|
=== Setting up
|
12
12
|
|
13
|
-
* Get a publisher_id and/or analytics_id from http://www.admob.com
|
13
|
+
* Get a publisher_id and/or analytics_id from http://www.admob.com and/or http://analytics.admob.com
|
14
14
|
* Add <tt>require "admob"</tt> to app/controllers/application.rb, or to any specific controller as needed.
|
15
15
|
* Provide some or all default settings in your environment.rb . e.g. :
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
require 'admob'
|
17
|
+
AdMob::config do |c|
|
18
|
+
c.publisher_id = 'YOUR_PUBLISHER_ID'
|
19
|
+
c.analytics_id = 'YOUR_ANALYTICS_ID'
|
20
|
+
c.timeout = 1
|
21
|
+
c.encoding = 'UTF-8'
|
22
|
+
c.raise_exceptions = false
|
23
|
+
c.cookie_domain = 'example.com'
|
24
|
+
end
|
24
25
|
* In a view, where you want an ad, place an ad request.
|
25
26
|
* Note: You must provide your publisher_id and/or analytics_id in the default setting, or when you make the ad request (see below).
|
26
27
|
|
28
|
+
=== Using Cookies
|
29
|
+
|
30
|
+
* AdMob now uses cookies to enhance ad targeting and analytics data.
|
31
|
+
* The easiest way to enable AdMob cookies on your website is to add the following code snippet to your ActionController::Base class (usually in app/controllers/application.rb)
|
32
|
+
* This will cause AdMob::set_cookie() to be executed on every request (the function will return immediately if a cookie does not need to be set)
|
33
|
+
|
34
|
+
require 'admob'
|
35
|
+
class ApplicationController < ActionController::Base
|
36
|
+
|
37
|
+
## begin AdMob cookie snippet ##
|
38
|
+
before_filter :admob_set_cookie
|
39
|
+
|
40
|
+
def admob_set_cookie
|
41
|
+
AdMob::set_cookie(request, cookies)
|
42
|
+
end
|
43
|
+
## end AdMob cookie snippet ##
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
=== Configuring Cookies (IMPORTANT if your site uses multiple subdomains)
|
48
|
+
|
49
|
+
* By default, the domain of the cookie is for the host that set it. This means that cookies set from a.example.com are not visible from b.example.com
|
50
|
+
* To allow AdMob cookies to be visible everywhere on your site, you need to set a default cookie domain in environment.rb
|
51
|
+
* The default cookie domain should be the root domain of your mobile site (e.g. "example.com", "example.co.uk")
|
52
|
+
|
53
|
+
require 'admob'
|
54
|
+
AdMob::config do |c|
|
55
|
+
c.cookie_domain = 'example.com' # if your main domain is www.example.com
|
56
|
+
c.cookie_domain = 'example.co.uk' # if your main domain is www.example.co.uk
|
57
|
+
end
|
58
|
+
|
27
59
|
=== Sample requests
|
28
60
|
|
29
61
|
==== If you've configured a default publisher and/or analytics id
|
@@ -50,12 +82,16 @@ See the documentation for #AdMob::request for a list of all params that can be s
|
|
50
82
|
|
51
83
|
== REQUIREMENTS:
|
52
84
|
|
53
|
-
* An AdMob publisher_id and/or analytics_id (get them at http://www.admob.com)
|
85
|
+
* An AdMob publisher_id and/or analytics_id (get them at http://www.admob.com and http://analytics.admob.com)
|
54
86
|
|
55
87
|
== INSTALL:
|
56
88
|
|
57
89
|
<tt>sudo gem install admob</tt>
|
58
90
|
|
91
|
+
== HELP:
|
92
|
+
|
93
|
+
Additional information can be found at http://developer.admob.com
|
94
|
+
|
59
95
|
== LICENSE:
|
60
96
|
|
61
97
|
(The BSD License)
|
@@ -68,4 +104,4 @@ Redistribution and use in source and binary forms, with or without modification,
|
|
68
104
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
69
105
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
70
106
|
|
71
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
107
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/lib/admob.rb
CHANGED
@@ -8,10 +8,10 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
|
8
8
|
# This module encapsulates functionality (ad requests, analytics requests) provided by AdMob. See README.txt for usage.
|
9
9
|
module AdMob
|
10
10
|
|
11
|
-
GEM_VERSION = '1.0
|
11
|
+
GEM_VERSION = '1.1.0'
|
12
12
|
|
13
13
|
ENDPOINT = URI.parse('http://r.admob.com/ad_source.php')
|
14
|
-
PUBCODE_VERSION = '
|
14
|
+
PUBCODE_VERSION = '20081105-RUBY-70e4a867449121c5'
|
15
15
|
DEFAULT_TIMEOUT = 1.0
|
16
16
|
|
17
17
|
# Make an AdMob ad/analytics request. The first param is the request variable from Rails; the second is a unique session
|
@@ -39,11 +39,6 @@ module AdMob
|
|
39
39
|
# [<tt>:timeout</tt>] override the default timeout value for this ad request in seconds, e.g. 2
|
40
40
|
# [<tt>:raise_exceptions</tt>] whether to raise exceptions when something goes wrong (defaults to false); exceptions will all be instances of AdMob::Error; a default can be set using <tt>AdMob::config {|c| c.raise_exceptions = true}</tt>
|
41
41
|
def self.request(request, session_id, params = {})
|
42
|
-
# Guarantee that only one analytics call gets made per request
|
43
|
-
if request.env['admob_analytics_request_issued'] == true
|
44
|
-
params[:analytics_request] = false
|
45
|
-
end
|
46
|
-
|
47
42
|
raise_exceptions = params[:raise_exceptions].nil? ? AdMob::Defaults.raise_exceptions : params[:raise_exceptions]
|
48
43
|
|
49
44
|
# Build the post request
|
@@ -61,27 +56,72 @@ module AdMob
|
|
61
56
|
conn.read_timeout = timeout
|
62
57
|
conn.open_timeout = timeout
|
63
58
|
begin
|
59
|
+
start = Time.now.getutc.to_f
|
64
60
|
response = conn.start {|http| http.request(req)}
|
65
|
-
contents = response.body
|
61
|
+
contents = response.body
|
66
62
|
rescue Timeout::Error => te
|
67
|
-
contents = %Q|<img src="http://t.admob.com/li.php/c.gif/#{post_data['s']}/1/#{timeout}/#{MD5.hexdigest(post_data['p'])}" alt="" width="1" height="1" />|
|
68
63
|
raise AdMob::Error.new("AdMob::request timed out; timeout was #{timeout}, elapsed time was #{Time.now.to_f - post_data['z']}") if raise_exceptions
|
69
64
|
rescue
|
70
65
|
raise AdMob::Error.new("AdMob::request encountered unexpected exception #{$!}") if raise_exceptions
|
71
66
|
ensure
|
72
67
|
contents ||= ''
|
68
|
+
lt = Time.now.getutc.to_f - start
|
73
69
|
end
|
74
|
-
|
70
|
+
|
75
71
|
# If appropriate, add the analytics pixel
|
76
|
-
if
|
77
|
-
|
72
|
+
if !request.env['admob_pixel_sent']
|
73
|
+
request.env['admob_pixel_sent'] = true
|
74
|
+
contents << '<img src="http://p.admob.com/e0?'
|
75
|
+
contents << "rt=#{post_data['rt']}&"
|
76
|
+
contents << "z=#{post_data['z']}&"
|
77
|
+
contents << "a=#{post_data['a']}&"
|
78
|
+
contents << "s=#{post_data['s']}&"
|
79
|
+
contents << "o=#{post_data['o']}&"
|
80
|
+
contents << "lt=%0.4f&" % lt
|
81
|
+
contents << "to=#{timeout}"
|
82
|
+
contents << '" alt="" width="1" height="1"/>'
|
78
83
|
end
|
79
84
|
|
80
85
|
contents
|
81
86
|
end
|
82
87
|
|
88
|
+
# This function should be called from an ActionController to set a cookie on behalf of AdMob.
|
89
|
+
# AdMob recommends using a before_filter in your ActionController::Base class (usually in app/controllers/application.rb) to call set_cookie on each request.
|
90
|
+
# Here is a sample application.rb.
|
91
|
+
# require 'admob'
|
92
|
+
# # Filters added to this controller apply to all controllers in the application.
|
93
|
+
# # Likewise, all the methods added will be available for all controllers.
|
94
|
+
#
|
95
|
+
# class ApplicationController < ActionController::Base
|
96
|
+
# before_filter :admob_set_cookie
|
97
|
+
#
|
98
|
+
# def admob_set_cookie
|
99
|
+
# AdMob::set_cookie(request, cookies)
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
def self.set_cookie(request, cookies)
|
103
|
+
# don't make a new cookie if one already exists
|
104
|
+
return if request.env['admobuu'] or cookies[:admobuu]
|
105
|
+
|
106
|
+
# make a new cookie
|
107
|
+
value = MD5.hexdigest(rand().to_s + request.user_agent + request.remote_ip + Time.now.to_f.to_s)
|
108
|
+
new_cookie = { :value => value,
|
109
|
+
:expires => Time.at(0x7fffffff), # end of 32 bit time
|
110
|
+
:path => "/" }
|
111
|
+
|
112
|
+
if AdMob::Defaults.cookie_domain
|
113
|
+
domain = AdMob::Defaults.cookie_domain
|
114
|
+
domain = '.' + domain if domain[0].chr != '.'
|
115
|
+
new_cookie[:domain] = domain
|
116
|
+
end
|
117
|
+
cookies[:admobuu] = new_cookie
|
118
|
+
|
119
|
+
# make this cookie visible to the current page
|
120
|
+
request.env['admobuu'] = value
|
121
|
+
end
|
122
|
+
|
83
123
|
# Provides access to AdMob config, used for setting default request info.
|
84
|
-
# Currently, can be used to set defaults for: publisher_id, analytics_id, ad encoding, request timeout,
|
124
|
+
# Currently, can be used to set defaults for: publisher_id, analytics_id, ad encoding, request timeout, cookie_domain,
|
85
125
|
# and whether exceptions are raised when something goes wrong.
|
86
126
|
# For example, in environment.rb:
|
87
127
|
# require 'admob'
|
@@ -91,6 +131,7 @@ module AdMob
|
|
91
131
|
# c.encoding = 'SJIS'
|
92
132
|
# c.timeout = 3
|
93
133
|
# c.raise_exceptions = true
|
134
|
+
# c.cookie_domain = 'example.com'
|
94
135
|
# end
|
95
136
|
def self.config
|
96
137
|
yield AdMob::Defaults
|
@@ -103,11 +144,11 @@ module AdMob
|
|
103
144
|
end
|
104
145
|
|
105
146
|
private
|
106
|
-
|
147
|
+
|
107
148
|
# Stores default values for AdMob requests. Set these defaults via AdMob::config.
|
108
149
|
class Defaults
|
109
150
|
class << self
|
110
|
-
attr_accessor :publisher_id, :analytics_id, :encoding, :timeout, :raise_exceptions
|
151
|
+
attr_accessor :publisher_id, :analytics_id, :encoding, :timeout, :raise_exceptions, :cookie_domain
|
111
152
|
end
|
112
153
|
end
|
113
154
|
|
@@ -119,7 +160,7 @@ private
|
|
119
160
|
encoding = params[:encoding] || AdMob::Defaults.encoding
|
120
161
|
|
121
162
|
# Determine the type of request
|
122
|
-
analytics_request = (params[:analytics_request] != false) && (!analytics_id.nil?) && (!analytics_id.strip.empty?)
|
163
|
+
analytics_request = (params[:analytics_request] != false) && (!analytics_id.nil?) && (!analytics_id.strip.empty?) && (!request.env['admob_pixel_sent'])
|
123
164
|
ad_request = (params[:ad_request] != false) && (!publisher_id.nil?) && (!publisher_id.strip.empty?)
|
124
165
|
|
125
166
|
case [ad_request, analytics_request]
|
@@ -128,27 +169,25 @@ private
|
|
128
169
|
when [false, true] then request_type = 1
|
129
170
|
when [true, true] then request_type = 2
|
130
171
|
end
|
131
|
-
|
132
|
-
# mark for this request so we don't make analytics calls again
|
133
|
-
request.env['admob_analytics_request_issued'] = true if analytics_request
|
134
|
-
|
172
|
+
|
135
173
|
# Build the basic request
|
136
174
|
post_data = {
|
137
|
-
'
|
138
|
-
'
|
175
|
+
'rt' => request_type,
|
176
|
+
'z' => Time.now.getutc.to_f,
|
139
177
|
'u' => request.user_agent,
|
140
178
|
'i' => request.remote_ip,
|
141
179
|
'p' => request.request_uri,
|
142
180
|
't' => MD5.hexdigest(session_id),
|
143
|
-
'ma' => params[:markup],
|
144
|
-
'rt' => request_type,
|
145
181
|
'v' => PUBCODE_VERSION,
|
182
|
+
'o' => request.cookies['admobuu'][0] || request.env['admobuu'],
|
183
|
+
's' => publisher_id,
|
184
|
+
'a' => analytics_id,
|
185
|
+
'ma' => params[:markup],
|
146
186
|
'd[pc]' => params[:postal_code],
|
147
187
|
'd[ac]' => params[:area_code],
|
148
188
|
'd[coord]' => params[:coordinates],
|
149
189
|
'd[dob]' => params[:dob],
|
150
190
|
'd[gender]' => params[:gender],
|
151
|
-
'z' => Time.now.to_f,
|
152
191
|
'k' => params[:keywords],
|
153
192
|
'search' => params[:search],
|
154
193
|
'f' => 'html',
|
@@ -158,7 +197,7 @@ private
|
|
158
197
|
|
159
198
|
# Add in headers
|
160
199
|
ignore_headers = Set['HTTP_PRAGMA', 'HTTP_CACHE_CONTROL', 'HTTP_CONNECTION',
|
161
|
-
'HTTP_USER_AGENT', 'HTTP_COOKIE', '
|
200
|
+
'HTTP_USER_AGENT', 'HTTP_COOKIE', 'ADMOB_PIXEL_SENT', 'ADMOBUU']
|
162
201
|
request.env.each {|k,v| post_data["h[#{k}]"] = v unless ignore_headers.include?(k.upcase.gsub(/-/,'_'))}
|
163
202
|
|
164
203
|
# Add in optional data
|
@@ -170,4 +209,4 @@ private
|
|
170
209
|
post_data.delete_if {|k,v| v.nil?}
|
171
210
|
end
|
172
211
|
|
173
|
-
end
|
212
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AdMobAdMob
|
@@ -9,17 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-05 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hoe
|
17
|
+
type: :development
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
23
|
+
version: 1.7.0
|
23
24
|
version:
|
24
25
|
description: Enables easy integration of AdMob ads into a RoR mobile site.
|
25
26
|
email: support@admob.comsupport@admob.com
|
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
61
|
requirements: []
|
61
62
|
|
62
63
|
rubyforge_project: admob
|
63
|
-
rubygems_version: 1.0
|
64
|
+
rubygems_version: 1.2.0
|
64
65
|
signing_key:
|
65
66
|
specification_version: 2
|
66
67
|
summary: Enables easy integration of AdMob ads into a RoR mobile site.
|