|
| 1 | +-- This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +-- License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +-- file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +--[[ |
| 6 | +# Pioneer Opt-in Enrollment |
| 7 | +
|
| 8 | +Plugin that estimates the number of users who have the Pioneer Opt-in |
| 9 | +add-on installed per-day. |
| 10 | +
|
| 11 | +See: https://bugzilla.mozilla.org/show_bug.cgi?id=1447331 |
| 12 | +
|
| 13 | +https://docs.telemetry.mozilla.org/concepts/data_pipeline.html#hindsight |
| 14 | +
|
| 15 | +## Sample Configuration |
| 16 | +
|
| 17 | +```lua |
| 18 | +filename = 'moz_pioneer_opt_in_estimates.lua' |
| 19 | +message_matcher = 'Type=="telemetry" && Fields[docType]=="main" && Fields[environment.addons] =~ "[email protected]"%' |
| 20 | +preserve_data = true |
| 21 | +ticker_interval = 60 |
| 22 | +``` |
| 23 | +
|
| 24 | +## Sample Output |
| 25 | +Keys are the date in `YEARMONTHDAY` format, values are the estimated number of |
| 26 | +users who sent a ping that included the Pioneer add-on that day. |
| 27 | +```json |
| 28 | +{ |
| 29 | + "20171001": 4523, |
| 30 | + "20171002": 5937, |
| 31 | + "20171003": 3002 |
| 32 | +} |
| 33 | +``` |
| 34 | +--]] |
| 35 | +require "cjson" |
| 36 | +require "hyperloglog" |
| 37 | + |
| 38 | +pioneer_day_hlls = {} |
| 39 | + |
| 40 | +function process_message() |
| 41 | + local day = read_message("Fields[submissionDate]") |
| 42 | + local hll = pioneer_day_hlls[day] |
| 43 | + if not hll then |
| 44 | + hll = hyperloglog.new() |
| 45 | + pioneer_day_hlls[day] = hll |
| 46 | + end |
| 47 | + hll:add(read_message("Fields[clientId]")) |
| 48 | + return 0 |
| 49 | +end |
| 50 | + |
| 51 | + |
| 52 | +function timer_event() |
| 53 | + local pioneer_day_counts = {} |
| 54 | + local count = 0 |
| 55 | + local earliest_day = nil |
| 56 | + for day, hll in pairs(pioneer_day_hlls) do |
| 57 | + pioneer_day_counts[day] = hll:count() |
| 58 | + count = count + 1 |
| 59 | + if not earliest_day or day < earliest_day then |
| 60 | + earliest_day = day |
| 61 | + end |
| 62 | + end |
| 63 | + inject_payload("json", "pioneer_opt_in_count", cjson.encode(pioneer_day_counts)) |
| 64 | + if count > 30 then |
| 65 | + pioneer_day_hlls[earliest_day] = nil |
| 66 | + end |
| 67 | +end |
0 commit comments