Module: CrowdMob::Installs
- Defined in:
- lib/installs.rb
Constant Summary collapse
- @@salt =
When you signed up for server-to-server installs tracking with CrowdMob, CrowdMob worked with you to determine a secure hashing algorithm, a salt, and a unique device identifier to meet your requirements. In this example, we’re SHA256 hashing MAC addresses, salted with the string “salt”. We typically recommend using your app’s secret key as your salt, but we can use any string that meets your requirements as a salt.
'salt'
Class Attribute Summary collapse
-
.app_permalink ⇒ Object
Returns the value of attribute app_permalink.
-
.app_secret_key ⇒ Object
Returns the value of attribute app_secret_key.
Class Method Summary collapse
Class Attribute Details
.app_permalink ⇒ Object
Returns the value of attribute app_permalink.
14 15 16 |
# File 'lib/installs.rb', line 14 def app_permalink @app_permalink end |
.app_secret_key ⇒ Object
Returns the value of attribute app_secret_key.
13 14 15 |
# File 'lib/installs.rb', line 13 def app_secret_key @app_secret_key end |
Class Method Details
.report(mac_address) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/installs.rb', line 40 def self.report(mac_address) url = CrowdMob.base_url + '/crave/verify_install.json' uri = URI.parse(url) # Hash the MAC address. If you already store the unique device # identifiers hashed, then this step is unnecessary. If you store the # device IDs hashed, you would've worked with CrowdMob's engineers to # implement a custom server-to-server installs tracking integration # solution. hashed_mac_address = Digest::SHA2.hexdigest(@@salt + mac_address) # Compute the secret hash. The secret hash is a required POST parameter # which prevents forged POST requests. This secret hash consists of your # app's permalink, a comma, the string "campaign_uuid", a comma, and the # previously hashed MAC address - salted with your app's secret key, all # SHA256 hashed. (Note that there's no comma between the secret key salt # and the permalink.) secret_hash = Digest::SHA2.hexdigest(@app_secret_key + @app_permalink + ',' + 'campaign_uuid' + ',' + hashed_mac_address) # The POST parameters: params = { 'permalink' => @app_permalink, 'uuid' => hashed_mac_address, 'uuid_type' => 'campaign_uuid', 'secret_hash' => secret_hash } # Finally, issue the POST request to CrowdMob's server: response, data = Net::HTTP.post_form(uri, params) json = JSON.parse(response.body) # Check for a 200 HTTP status code. This code denotes successful install # tracking. # puts "HTTP status code: #{response.code}" # puts "CrowdMob internal (action) status code: #{json['action_status']}" # This table explains what the different status code combinations # denote: # HTTP Status Code CrowdMob Internal Status Code Meaning # ---------------- ----------------------------- ------- # 400 1001 You didn't supply your app's permalink as an HTTP POST parameter. # 400 1002 You didn't specify the unique device identifier type as an HTTP POST parameter. (In the case of server-to-server installs tracking, this parameter should be the string "campaign_uuid".) # 400 1003 You didn't specify the unique device identifier as an HTTP POST parameter. (Typically a salted hashed MAC address, but could be some other unique device identifier that you collect on your server.) # 404 1004 The app permalink that you specified doesn't correspond to any app registered on CrowdMob's server. # 403 1005 The secret hash that you computed doesn't correspond to the secret hash that CrowdMob's server computed. (This could be a forged request?) # 200 Any CrowdMob's server successfully tracked the install. end |