Permalink
Browse files

Merging README conflict

  • Loading branch information...
2 parents 5d6faf0 + b226cb5 commit 825d757d463d024280e36fe6a3291ce41cb8fe6f @jkrall jkrall committed Mar 15, 2011
Showing with 80 additions and 1 deletion.
  1. +2 −0 README.rdoc
  2. +3 −1 example/config/analytical.yml
  3. +49 −0 lib/analytical/modules/quantcast.rb
  4. +26 −0 spec/analytical/modules/quantcast.rb
View
@@ -16,6 +16,7 @@ Service implementations include:
* Clicktale
* Google Website Optimizer
* Performancing
+* Quantcast[http://www.quantcast.com]
== Usage
@@ -100,6 +101,7 @@ These fine folks have contributed patches and new features to this project:
* {Adam Anderson}[http://github.com/scudco]
* {Bryan Liles}[http://github.com/bryanl]
+* {Nathan Phelps}[http://github.com/nwp]
Thanks guys!
@@ -25,4 +25,6 @@ chartbeat:
comscore:
key: comscore_12345
optimizely:
- key: optimizely_12345
+ key: optimizely_12345
+quantcast:
+ key: p-abc123
@@ -0,0 +1,49 @@
+module Analytical
+ module Modules
+ class Quantcast
+ include Analytical::Modules::Base
+
+ def initialize(options={})
+ super
+ @tracking_command_location = [:head_append, :body_append]
+ end
+
+ def init_javascript(location)
+ init_location(location) do
+ case location.to_sym
+ when :head_append
+ js = <<-HTML
+ <!-- Analytical Head Init: Quantcast -->
+ <script type="text/javascript">
+ var _qevents = _qevents || [];
+
+ (function() {
+ var elem = document.createElement('script');
+
+ elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js";
+ elem.async = true;
+ elem.type = "text/javascript";
+ var scpt = document.getElementsByTagName('script')[0];
+ scpt.parentNode.insertBefore(elem, scpt);
+ })();
+ </script>
+ HTML
+ js
+ when :body_append
+ js = <<-HTML
+ <!-- Analytical Body Init: Quantcast -->
+ <script type="text/javascript">
+ _qevents.push( { qacct:"#{options[:key]}"} );
+ </script>
+ <noscript>
+ <div style="display: none;"><img src="//pixel.quantserve.com/pixel/#{options[:key]}.gif" height="1" width="1" alt="Quantcast"/></div>
+ </noscript>
+ HTML
+ js
+ end
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,26 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe "Analytical::Modules::Quantcast" do
+ before(:each) do
+ @parent = mock('api', :options=>{:quantcast=>{:key=>1234}})
+ end
+ describe 'on initialize' do
+ it 'should set the command_location' do
+ a = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>1234
+ a.tracking_command_location.should == [:head_append, :body_append]
+ end
+ it 'should set the options' do
+ a = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>12345
+ a.options.should == {:key=>12345, :parent=>@parent}
+ end
+ end
+ describe '#init_javascript' do
+ it 'should return the init javascript' do
+ @api = Analytical::Modules::Quantcast.new :parent=>@parent, :key=>12345
+ @api.init_javascript(:head_prepend).should =~ ''
+ @api.init_javascript(:head_append).should == /var._qevents.=._qevents.\|\|.\[\];/
+ @api.init_javascript(:body_prepend).should == ''
+ @api.init_javascript(:body_append).should =~ /_qevents.push\(.\{.qacct:"12345"\} \);/
+ end
+ end
+end

0 comments on commit 825d757

Please sign in to comment.