Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions moon/autorun/gm_mixpanel.moon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ playerIdentifierEvent = "Mixpanel_PlayerIdentifier"
if SERVER
AddCSLuaFile "includes/modules/mixpanel.lua"
AddCSLuaFile "gm_mixpanel/cl_mixpanel.lua"
AddCSLuaFile "gm_mixpanel/cl_menu.lua"
AddCSLuaFile "gm_mixpanel/base.lua"

util.AddNetworkString playerIdentifierEvent
Expand Down
8 changes: 6 additions & 2 deletions moon/gm_mixpanel/base.moon
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class MixpanelBase
@MAX_QUEUE_SIZE = 50
@eventQueue = {}

_getToken: => getToken!

_getTimestamp: => getTimestamp!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really following why you did this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other classes inherit this, but these values are defined locally in this file

_clearQueue: =>
queueSize = #@eventQueue
for i = 1, queueSize
Expand Down Expand Up @@ -73,8 +77,8 @@ class MixpanelBase
_trackEvent: (eventName, eventProperties, reliable=false) =>
@_startQueueGroomer! unless timerExists @queueTimer

eventProperties.token = getToken!
eventProperties.time = getTimestamp!
eventProperties.token = @_getToken!
eventProperties.time = @_getTimestamp!

data =
event: eventName
Expand Down
13 changes: 13 additions & 0 deletions moon/gm_mixpanel/cl_menu.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import AddToolCategory, AddToolMenuOption from spawnmenu
optOut = GetConVar "mixpanel_opt_out"

populatePanel = (panel) ->
label = "Opt out of player telemetry"
panel\CheckBox label, "mixpanel_opt_out"

hook.Add "AddToolMenuCategories", "Mixpanel_Menu_Category", ->
AddToolCategory "Options", "Telemetry", "Telemetry"

hook.Add "PopulateToolMenu", "Mixpanel_MenuOption", ->
AddToolMenuOption "Options", "Telemetry", "mixpanel_opt_out", "Telemetry", "", "", (panel) ->
populatePanel panel
8 changes: 6 additions & 2 deletions moon/gm_mixpanel/cl_mixpanel.moon
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import Merge from table
MixpanelBase = include "gm_mixpanel/base.lua"

optOut = CreateClientConVar "mixpanel_opt_out", 0, true, true, "", 0, 1
include "gm_mixpanel/cl_menu.lua"

class MixpanelInterface extends MixpanelBase
getIdentifiers = -> {
distinct_id: LocalPlayer!\SteamID64!
ip: LocalPlayer!.mixpanelIdentifier
}

TrackEvent: (name, properties={}, reliable=false) =>
Merge properties, getIdentifiers!
return if optOut\GetBool!

Merge properties, getIdentifiers!
@_trackEvent name, properties, reliable

export Mixpanel = MixpanelInterface!
3 changes: 3 additions & 0 deletions moon/gm_mixpanel/sv_mixpanel.moon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CRC from util
import Merge from table
MixpanelBase = include "gm_mixpanel/base.lua"
include "gm_mixpanel/sv_profile.lua"

class MixpanelInterface extends MixpanelBase
_getPlyIdentifiers: (ply) => {
Expand All @@ -13,6 +14,8 @@ class MixpanelInterface extends MixpanelBase
@_trackEvent name, properties, reliable

TrackPlyEvent: (name, ply, properties={}, reliable=false) =>
return if ply\GetInfoNum("mixpanel_opt_out", 0) == 1

Merge properties, @_getPlyIdentifiers ply
@_trackEvent name, properties, reliable

Expand Down
35 changes: 35 additions & 0 deletions moon/gm_mixpanel/sv_profile.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import CRC from util
timerExists = timer.Exists
MixpanelBase = include "gm_mixpanel/base.lua"

class MixpanelProfileInterface extends MixpanelBase
new: =>
super!
@trackUrl = "http://api.mixpanel.com/engage"
@queueTimer = "Mixpanel_ProfileQueueGroomer"

_getPlyIdentifiers: (ply) => {
distinct_id: ply\SteamID64!
ip: CRC ply\IPAddress!
}

_trackEvent: => error "Not Implemented!"

_trackProfile: (plyData) =>
@_startQueueGroomer! unless timerExists @queueTimer

plyData.token = @_getToken!
plyData.time = @_getTimestamp!

@_queueEvent data

MakeProfile: (ply) =>
return if ply\GetInfoNum("mixpanel_opt_out", 0) == 1

data = @_getPlyIdentifiers ply
@_trackProfile @_getPlyIdentifiers ply

profileInterface = MixpanelProfileInterface!

hook.Add "PlayerInitialSpawn", "Mixpanel_TrackProfile", (ply) ->
profileInterface\MakeProfile ply