Class: Crowdskout::Components::TrackingCode

Inherits:
Component
  • Object
show all
Defined in:
lib/crowdskout/components/quartermaster/tracking_code.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

get_value, #to_hash, to_hash_value, #to_json

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 10

def client
  @client
end

#organizationObject

Returns the value of attribute organization.



10
11
12
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 10

def organization
  @organization
end

#sourceObject

Returns the value of attribute source.



10
11
12
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 10

def source
  @source
end

Class Method Details

.create(props) ⇒ TrackingCode

Factory method to create a TrackingCode object from a json string



15
16
17
18
19
20
21
22
23
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 15

def self.create(props)
  obj = TrackingCode.new
  if props
    props.each do |key, value|
      obj.send("#{key}=", value.to_i) if obj.respond_to? key
    end
  end
  obj
end

Instance Method Details

#tracking_code_sourceString

Generate the crowdskout tracking source based on the codes



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 27

def tracking_code_source
        if !source.nil? && !organization.nil? && !client.nil?
%{<!-- Crowdskout -->
  <script>
  (function(l,o,v,e,d) {
    l.cs=l.cs || function() {cs.q.push(arguments);};
    cs.q=cs.q||[];cs.apiUrl=d;cs('pageView');
    l.sourceId = #{source};l.clientId = #{client};l.organizationId = #{organization};
    var a=o.getElementsByTagName(v)[0];var b=o.createElement(v);b.src=e+'/analytics.js';a.parentNode.insertBefore(b,a);
    })(window, document, 'script', '//s.crowdskout.com','https://a.crowdskout.com');
    </script>}
  else
    %{
      Tracking Codes Error
      Source: #{source}
      Organization: #{organization}
      Client: #{client}
    }
  end
end