Class: Crowdskout::Components::TrackingCode
- Defined in:
- lib/crowdskout/components/quartermaster/tracking_code.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
-
.create(props) ⇒ TrackingCode
Factory method to create a TrackingCode object from a json string.
Instance Method Summary collapse
-
#tracking_code_source ⇒ String
Generate the crowdskout tracking source based on the codes.
-
#tracking_code_source_no_script ⇒ String
Generate the crowdskout tracking source without script tags and minimized based on the codes.
Methods inherited from Component
get_value, #to_hash, to_hash_value, #to_json
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 10 def client @client end |
#organization ⇒ Object
Returns the value of attribute organization.
10 11 12 |
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 10 def organization @organization end |
#source ⇒ Object
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_source ⇒ String
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 27 def tracking_code_source if !source.nil? && !organization.nil? && !client.nil? %{ <!-- Crowdskout --> <script> (function(s,k,o,u,t){ s.cs=s.cs||function(){cs.q.push(arguments);}; cs.q=cs.q||[];cs.apiUrl=t; s.sourceId = #{source};s.clientId = #{client};s.organizationId = #{organization}; var a=k.getElementsByTagName(o)[0];var b=k.createElement(o);b.src=u+'/analytics.js'; b.onreadystatechange = b.onload = function() { if ((!b.readyState || /loaded|complete/.test(b.readyState))) { s._csCalledBackup = s._csCalled; s._csCalled = function(type, body) { if (type === 'page-view') { s.cspageviewuuid = body.uuid; } if (s._csCalledBackup) { s._csCalledBackup(type, body); } }; } }; 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 |
#tracking_code_source_no_script ⇒ String
Generate the crowdskout tracking source without script tags and minimized based on the codes
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/crowdskout/components/quartermaster/tracking_code.rb', line 66 def tracking_code_source_no_script if !source.nil? && !organization.nil? && !client.nil? script = "(function(s,k,o,u,t){s.cs=s.cs||function(){cs.q.push(arguments);};cs.q=cs.q||[];cs.apiUrl=t;s.sourceId = #{source};s.clientId = #{client};s.organizationId = #{organization};var a=k.getElementsByTagName(o)[0];var b=k.createElement(o);b.src=u+'/analytics.js';b.onreadystatechange = b.onload = function() {if ((!b.readyState || /loaded|complete/.test(b.readyState))) {s._csCalledBackup = s._csCalled;s._csCalled = function(type, body) {if (type === 'page-view') {s.cspageviewuuid = body.uuid;} if (s._csCalledBackup) {s._csCalledBackup(type, body);}};}};a.parentNode.insertBefore(b,a);})(window,document,'script','//s.crowdskout.com','https://a.crowdskout.com');" else %{ Tracking Codes Error Source: #{source} Organization: #{organization} Client: #{client} } end end |