tracks.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. package analytics
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. segment "gopkg.in/segmentio/analytics-go.v3"
  5. )
  6. type segmentTrack interface {
  7. getUserId() string
  8. getEvent() SegmentEvent
  9. getProperties() segment.Properties
  10. }
  11. type defaultTrackOpts struct {
  12. AdditionalProps map[string]interface{}
  13. }
  14. type defaultSegmentTrack struct {
  15. event SegmentEvent
  16. properties segmentProperties
  17. }
  18. func getDefaultSegmentTrack(additionalProps map[string]interface{}, event SegmentEvent) *defaultSegmentTrack {
  19. props := newSegmentProperties()
  20. props.addAdditionalProperties(additionalProps)
  21. return &defaultSegmentTrack{
  22. event: event,
  23. properties: props,
  24. }
  25. }
  26. func (t *defaultSegmentTrack) getEvent() SegmentEvent {
  27. return t.event
  28. }
  29. func (t *defaultSegmentTrack) getProperties() segment.Properties {
  30. props := segment.NewProperties()
  31. for key, val := range t.properties {
  32. props = props.Set(key, val)
  33. }
  34. return props
  35. }
  36. type segmentProperties map[string]interface{}
  37. func newSegmentProperties() segmentProperties {
  38. props := make(map[string]interface{})
  39. return props
  40. }
  41. func (p segmentProperties) addProjectProperties(opts *ProjectScopedTrackOpts) {
  42. p["proj_id"] = opts.ProjectID
  43. }
  44. func (p segmentProperties) addClusterProperties(opts *ClusterScopedTrackOpts) {
  45. p["cluster_id"] = opts.ClusterID
  46. }
  47. func (p segmentProperties) addRegistryProperties(opts *RegistryScopedTrackOpts) {
  48. p["registry_id"] = opts.RegistryID
  49. }
  50. func (p segmentProperties) addApplicationProperties(opts *ApplicationScopedTrackOpts) {
  51. p["app_name"] = opts.Name
  52. p["app_namespace"] = opts.Namespace
  53. p["chart_name"] = opts.ChartName
  54. }
  55. func (p segmentProperties) addAdditionalProperties(props map[string]interface{}) {
  56. for key, val := range props {
  57. p[key] = val
  58. }
  59. }
  60. // UserCreateTrackOpts are the options for creating a track when a user is created
  61. type UserCreateTrackOpts struct {
  62. *UserScopedTrackOpts
  63. Email string
  64. FirstName string
  65. LastName string
  66. CompanyName string
  67. ReferralMethod string
  68. }
  69. // UserCreateTrack returns a track for when a user is created
  70. func UserCreateTrack(opts *UserCreateTrackOpts) segmentTrack {
  71. additionalProps := make(map[string]interface{})
  72. additionalProps["email"] = opts.Email
  73. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  74. additionalProps["company"] = opts.CompanyName
  75. additionalProps["referral_method"] = opts.ReferralMethod
  76. return getSegmentUserTrack(
  77. opts.UserScopedTrackOpts,
  78. getDefaultSegmentTrack(additionalProps, UserCreate),
  79. )
  80. }
  81. // UserCreateTrackOpts are the options for creating a track when a user's email is verified
  82. type UserVerifyEmailTrackOpts struct {
  83. *UserScopedTrackOpts
  84. Email string
  85. }
  86. // UserVerifyEmailTrack returns a track for when a user's email is verified
  87. func UserVerifyEmailTrack(opts *UserVerifyEmailTrackOpts) segmentTrack {
  88. additionalProps := make(map[string]interface{})
  89. additionalProps["email"] = opts.Email
  90. return getSegmentUserTrack(
  91. opts.UserScopedTrackOpts,
  92. getDefaultSegmentTrack(additionalProps, UserVerifyEmail),
  93. )
  94. }
  95. // ProjectCreateDeleteTrackOpts are the options for creating a track when a project is created or deleted
  96. type ProjectCreateDeleteTrackOpts struct {
  97. *ProjectScopedTrackOpts
  98. Email string
  99. FirstName string
  100. LastName string
  101. CompanyName string
  102. }
  103. // ProjectConnectTrack returns a track for when a project is connected
  104. func ProjectConnectTrack(opts *ProjectCreateDeleteTrackOpts) segmentTrack {
  105. additionalProps := make(map[string]interface{})
  106. additionalProps["email"] = opts.Email
  107. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  108. additionalProps["company"] = opts.CompanyName
  109. return getSegmentProjectTrack(
  110. opts.ProjectScopedTrackOpts,
  111. getDefaultSegmentTrack(additionalProps, ProjectConnect),
  112. )
  113. }
  114. // ProjectCreateTrack returns a track for when a project is created
  115. func ProjectCreateTrack(opts *ProjectCreateDeleteTrackOpts) segmentTrack {
  116. additionalProps := make(map[string]interface{})
  117. additionalProps["email"] = opts.Email
  118. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  119. additionalProps["company"] = opts.CompanyName
  120. return getSegmentProjectTrack(
  121. opts.ProjectScopedTrackOpts,
  122. getDefaultSegmentTrack(additionalProps, ProjectCreate),
  123. )
  124. }
  125. // ProjectDeleteTrack returns a track for when a project is deleted
  126. func ProjectDeleteTrack(opts *ProjectCreateDeleteTrackOpts) segmentTrack {
  127. additionalProps := make(map[string]interface{})
  128. additionalProps["email"] = opts.Email
  129. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  130. additionalProps["company"] = opts.CompanyName
  131. return getSegmentProjectTrack(
  132. opts.ProjectScopedTrackOpts,
  133. getDefaultSegmentTrack(additionalProps, ProjectDelete),
  134. )
  135. }
  136. // ClusterDeleteTrackOpts are the options for creating a track when a cluster is deleted
  137. type ClusterDeleteTrackOpts struct {
  138. *ProjectScopedTrackOpts
  139. Email string
  140. FirstName string
  141. LastName string
  142. CompanyName string
  143. }
  144. // ClusterDeleteTrack returns a track for when a cluster is deleted
  145. func ClusterDeleteTrack(opts *ClusterDeleteTrackOpts) segmentTrack {
  146. additionalProps := make(map[string]interface{})
  147. additionalProps["email"] = opts.Email
  148. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  149. additionalProps["company"] = opts.CompanyName
  150. return getSegmentProjectTrack(
  151. opts.ProjectScopedTrackOpts,
  152. getDefaultSegmentTrack(additionalProps, ClusterDelete),
  153. )
  154. }
  155. // CostConsentOpenedTrackOpts are the options for creating a track when a user opens the cost consent
  156. type CostConsentOpenedTrackOpts struct {
  157. *UserScopedTrackOpts
  158. Provider string
  159. Email string
  160. FirstName string
  161. LastName string
  162. CompanyName string
  163. }
  164. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  165. func CostConsentOpenedTrack(opts *CostConsentOpenedTrackOpts) segmentTrack {
  166. additionalProps := make(map[string]interface{})
  167. additionalProps["provider"] = opts.Provider
  168. additionalProps["email"] = opts.Email
  169. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  170. additionalProps["company"] = opts.CompanyName
  171. return getSegmentUserTrack(
  172. opts.UserScopedTrackOpts,
  173. getDefaultSegmentTrack(additionalProps, CostConsentOpened),
  174. )
  175. }
  176. // CostConsentCompletedTrackOpts are the options for creating a track when a user completes the cost consent
  177. type CostConsentCompletedTrackOpts struct {
  178. *UserScopedTrackOpts
  179. Provider string
  180. Email string
  181. FirstName string
  182. LastName string
  183. CompanyName string
  184. }
  185. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  186. func CostConsentCompletedTrack(opts *CostConsentCompletedTrackOpts) segmentTrack {
  187. additionalProps := make(map[string]interface{})
  188. additionalProps["provider"] = opts.Provider
  189. additionalProps["email"] = opts.Email
  190. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  191. additionalProps["company"] = opts.CompanyName
  192. return getSegmentUserTrack(
  193. opts.UserScopedTrackOpts,
  194. getDefaultSegmentTrack(additionalProps, CostConsentComplete),
  195. )
  196. }
  197. // AWSInputTrackOpts are the options for creating a track when a user inputs a complete AWS account ID
  198. type AWSInputTrackOpts struct {
  199. *ProjectScopedTrackOpts
  200. Email string
  201. FirstName string
  202. LastName string
  203. CompanyName string
  204. AccountId string
  205. }
  206. // AWSInputTrack returns a track for when a user inputs a complete AWS account ID
  207. func AWSInputTrack(opts *AWSInputTrackOpts) segmentTrack {
  208. additionalProps := make(map[string]interface{})
  209. additionalProps["email"] = opts.Email
  210. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  211. additionalProps["company"] = opts.CompanyName
  212. additionalProps["account_id"] = opts.AccountId
  213. return getSegmentProjectTrack(
  214. opts.ProjectScopedTrackOpts,
  215. getDefaultSegmentTrack(additionalProps, AWSInputted),
  216. )
  217. }
  218. type AWSRedirectOpts struct {
  219. *ProjectScopedTrackOpts
  220. Email string
  221. FirstName string
  222. LastName string
  223. CompanyName string
  224. AccountId string
  225. CloudformationURL string
  226. LoginURL string
  227. ExternalId string
  228. }
  229. // AWSCloudformationRedirectSuccess returns a track for when a user clicks 'grant permissions' and gets redirected to cloudformation
  230. func AWSCloudformationRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  231. additionalProps := make(map[string]interface{})
  232. additionalProps["email"] = opts.Email
  233. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  234. additionalProps["company"] = opts.CompanyName
  235. additionalProps["account_id"] = opts.AccountId
  236. additionalProps["cloudformation_url"] = opts.CloudformationURL
  237. additionalProps["external_id"] = opts.ExternalId
  238. return getSegmentProjectTrack(
  239. opts.ProjectScopedTrackOpts,
  240. getDefaultSegmentTrack(additionalProps, AWSCloudformationRedirect),
  241. )
  242. }
  243. // AWSLoginRedirectSuccess returns a track for when a user is prompted to login to AWS
  244. func AWSLoginRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  245. additionalProps := make(map[string]interface{})
  246. additionalProps["email"] = opts.Email
  247. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  248. additionalProps["company"] = opts.CompanyName
  249. additionalProps["account_id"] = opts.AccountId
  250. additionalProps["login_url"] = opts.LoginURL
  251. return getSegmentProjectTrack(
  252. opts.ProjectScopedTrackOpts,
  253. getDefaultSegmentTrack(additionalProps, AWSLoginRedirect),
  254. )
  255. }
  256. type AWSCreateIntegrationOpts struct {
  257. *ProjectScopedTrackOpts
  258. Email string
  259. FirstName string
  260. LastName string
  261. CompanyName string
  262. AccountId string
  263. ExternalId string
  264. ErrorMessage string
  265. }
  266. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  267. func AWSCreateIntegrationSucceeded(opts *AWSCreateIntegrationOpts) segmentTrack {
  268. additionalProps := make(map[string]interface{})
  269. additionalProps["email"] = opts.Email
  270. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  271. additionalProps["company"] = opts.CompanyName
  272. additionalProps["account_id"] = opts.AccountId
  273. return getSegmentProjectTrack(
  274. opts.ProjectScopedTrackOpts,
  275. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationSuccess),
  276. )
  277. }
  278. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  279. func AWSCreateIntegrationFailed(opts *AWSCreateIntegrationOpts) segmentTrack {
  280. additionalProps := make(map[string]interface{})
  281. additionalProps["email"] = opts.Email
  282. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  283. additionalProps["company"] = opts.CompanyName
  284. additionalProps["account_id"] = opts.AccountId
  285. additionalProps["error_message"] = opts.ErrorMessage
  286. additionalProps["external_id"] = opts.ExternalId
  287. return getSegmentProjectTrack(
  288. opts.ProjectScopedTrackOpts,
  289. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationFailure),
  290. )
  291. }
  292. // CredentialStepTrackOpts are the options for creating a track when a user completes the credential step
  293. type CredentialStepTrackOpts struct {
  294. *UserScopedTrackOpts
  295. }
  296. // CredentialStepTrack returns a track for when a user completes the credential step
  297. func CredentialStepTrack(opts *CredentialStepTrackOpts) segmentTrack {
  298. additionalProps := make(map[string]interface{})
  299. return getSegmentUserTrack(
  300. opts.UserScopedTrackOpts,
  301. getDefaultSegmentTrack(additionalProps, CredentialStepComplete),
  302. )
  303. }
  304. // PreProvisionCheckTrackOpts are the options for creating a track when a user checks if they can provision
  305. type PreProvisionCheckTrackOpts struct {
  306. *ProjectScopedTrackOpts
  307. Email string
  308. FirstName string
  309. LastName string
  310. CompanyName string
  311. }
  312. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  313. func PreProvisionCheckTrack(opts *PreProvisionCheckTrackOpts) segmentTrack {
  314. additionalProps := make(map[string]interface{})
  315. additionalProps["email"] = opts.Email
  316. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  317. additionalProps["company"] = opts.CompanyName
  318. return getSegmentProjectTrack(
  319. opts.ProjectScopedTrackOpts,
  320. getDefaultSegmentTrack(additionalProps, PreProvisionCheck),
  321. )
  322. }
  323. // ProvisioningAttemptedTrackOpts are the options for creating a track when a user attempts provisioning
  324. type ProvisioningAttemptTrackOpts struct {
  325. *ProjectScopedTrackOpts
  326. Email string
  327. FirstName string
  328. LastName string
  329. CompanyName string
  330. ErrorMessage string
  331. Region string
  332. Provider string
  333. }
  334. // ProvisioningAttemptTrack returns a track for when a user attempts provisioning
  335. func ProvisioningAttemptTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  336. additionalProps := make(map[string]interface{})
  337. additionalProps["email"] = opts.Email
  338. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  339. additionalProps["company"] = opts.CompanyName
  340. additionalProps["region"] = opts.Region
  341. additionalProps["provider"] = opts.Provider
  342. return getSegmentProjectTrack(
  343. opts.ProjectScopedTrackOpts,
  344. getDefaultSegmentTrack(additionalProps, ProvisioningAttempted),
  345. )
  346. }
  347. // QuotaIncreaseAttemptTrack returns a track for when a user attempts provisioning
  348. func QuotaIncreaseAttemptTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  349. additionalProps := make(map[string]interface{})
  350. additionalProps["email"] = opts.Email
  351. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  352. additionalProps["company"] = opts.CompanyName
  353. additionalProps["region"] = opts.Region
  354. additionalProps["provider"] = opts.Provider
  355. return getSegmentProjectTrack(
  356. opts.ProjectScopedTrackOpts,
  357. getDefaultSegmentTrack(additionalProps, QuotaIncreaseRequested),
  358. )
  359. }
  360. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  361. func ProvisionFailureTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  362. additionalProps := make(map[string]interface{})
  363. additionalProps["email"] = opts.Email
  364. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  365. additionalProps["company"] = opts.CompanyName
  366. additionalProps["error_message"] = opts.ErrorMessage
  367. additionalProps["region"] = opts.Region
  368. return getSegmentProjectTrack(
  369. opts.ProjectScopedTrackOpts,
  370. getDefaultSegmentTrack(additionalProps, ProvisioningFailure),
  371. )
  372. }
  373. // ClusterProvisioningStartTrackOpts are the options for creating a track when a cluster
  374. // has started provisioning
  375. type ClusterProvisioningStartTrackOpts struct {
  376. // note that this is a project-scoped track, since the cluster has not been created yet
  377. *ProjectScopedTrackOpts
  378. ClusterType types.InfraKind
  379. InfraID uint
  380. }
  381. // ClusterProvisioningStartTrack returns a track for when a cluster
  382. // has started provisioning
  383. func ClusterProvisioningStartTrack(opts *ClusterProvisioningStartTrackOpts) segmentTrack {
  384. additionalProps := make(map[string]interface{})
  385. additionalProps["cluster_type"] = opts.ClusterType
  386. additionalProps["infra_id"] = opts.InfraID
  387. return getSegmentProjectTrack(
  388. opts.ProjectScopedTrackOpts,
  389. getDefaultSegmentTrack(additionalProps, ClusterProvisioningStart),
  390. )
  391. }
  392. // ClusterProvisioningErrorTrackOpts are the options for creating a track when a cluster
  393. // has experienced a provisioning error
  394. type ClusterProvisioningErrorTrackOpts struct {
  395. // note that this is a project-scoped track, since the cluster has not been created yet
  396. *ProjectScopedTrackOpts
  397. ClusterType types.InfraKind
  398. InfraID uint
  399. }
  400. // ClusterProvisioningErrorTrack returns a track for when a cluster
  401. // has experienced a provisioning error
  402. func ClusterProvisioningErrorTrack(opts *ClusterProvisioningErrorTrackOpts) segmentTrack {
  403. additionalProps := make(map[string]interface{})
  404. additionalProps["cluster_type"] = opts.ClusterType
  405. additionalProps["infra_id"] = opts.InfraID
  406. return getSegmentProjectTrack(
  407. opts.ProjectScopedTrackOpts,
  408. getDefaultSegmentTrack(additionalProps, ClusterProvisioningError),
  409. )
  410. }
  411. // ClusterProvisioningSuccessTrackOpts are the options for creating a track when a cluster
  412. // has successfully provisioned
  413. type ClusterProvisioningSuccessTrackOpts struct {
  414. *ClusterScopedTrackOpts
  415. ClusterType types.InfraKind
  416. InfraID uint
  417. }
  418. // ClusterProvisioningSuccessTrack returns a new track for when a cluster
  419. // has successfully provisioned
  420. func ClusterProvisioningSuccessTrack(opts *ClusterProvisioningSuccessTrackOpts) segmentTrack {
  421. additionalProps := make(map[string]interface{})
  422. additionalProps["cluster_type"] = opts.ClusterType
  423. additionalProps["infra_id"] = opts.InfraID
  424. return getSegmentClusterTrack(
  425. opts.ClusterScopedTrackOpts,
  426. getDefaultSegmentTrack(additionalProps, ClusterProvisioningSuccess),
  427. )
  428. }
  429. // ClusterConnectionStartTrackOpts are the options for creating a track when a cluster
  430. // connection has started
  431. type ClusterConnectionStartTrackOpts struct {
  432. // note that this is a project-scoped track, since the cluster has not been created yet
  433. *ProjectScopedTrackOpts
  434. ClusterCandidateID uint
  435. }
  436. // ClusterConnectionStartTrack returns a new track for when a cluster
  437. // connection has started
  438. func ClusterConnectionStartTrack(opts *ClusterConnectionStartTrackOpts) segmentTrack {
  439. additionalProps := make(map[string]interface{})
  440. additionalProps["cc_id"] = opts.ClusterCandidateID
  441. return getSegmentProjectTrack(
  442. opts.ProjectScopedTrackOpts,
  443. getDefaultSegmentTrack(additionalProps, ClusterConnectionStart),
  444. )
  445. }
  446. // ClusterConnectionSuccessTrackOpts are the options for creating a track when a cluster
  447. // connection has finished
  448. type ClusterConnectionSuccessTrackOpts struct {
  449. *ClusterScopedTrackOpts
  450. ClusterCandidateID uint
  451. }
  452. // ClusterConnectionSuccessTrack returns a new track for when a cluster
  453. // connection has finished
  454. func ClusterConnectionSuccessTrack(opts *ClusterConnectionSuccessTrackOpts) segmentTrack {
  455. additionalProps := make(map[string]interface{})
  456. additionalProps["cc_id"] = opts.ClusterCandidateID
  457. return getSegmentClusterTrack(
  458. opts.ClusterScopedTrackOpts,
  459. getDefaultSegmentTrack(additionalProps, ClusterConnectionSuccess),
  460. )
  461. }
  462. // RegistryConnectionStartTrackOpts are the options for creating a track when a registry
  463. // connection has started
  464. type RegistryConnectionStartTrackOpts struct {
  465. // note that this is a project-scoped track, since the cluster has not been created yet
  466. *ProjectScopedTrackOpts
  467. // a random id assigned to this connection request
  468. FlowID string
  469. }
  470. // RegistryConnectionStartTrack returns a new track for when a registry
  471. // connection has started
  472. func RegistryConnectionStartTrack(opts *RegistryConnectionStartTrackOpts) segmentTrack {
  473. additionalProps := make(map[string]interface{})
  474. additionalProps["flow_id"] = opts.FlowID
  475. return getSegmentProjectTrack(
  476. opts.ProjectScopedTrackOpts,
  477. getDefaultSegmentTrack(additionalProps, RegistryConnectionStart),
  478. )
  479. }
  480. // RegistryConnectionSuccessTrackOpts are the options for creating a track when a registry
  481. // connection has completed
  482. type RegistryConnectionSuccessTrackOpts struct {
  483. *RegistryScopedTrackOpts
  484. // a random id assigned to this connection request
  485. FlowID string
  486. }
  487. // RegistryConnectionSuccessTrack returns a new track for when a registry
  488. // connection has completed
  489. func RegistryConnectionSuccessTrack(opts *RegistryConnectionSuccessTrackOpts) segmentTrack {
  490. additionalProps := make(map[string]interface{})
  491. additionalProps["flow_id"] = opts.FlowID
  492. return getSegmentRegistryTrack(
  493. opts.RegistryScopedTrackOpts,
  494. getDefaultSegmentTrack(additionalProps, RegistryConnectionSuccess),
  495. )
  496. }
  497. // GithubConnectionStartTrackOpts are the options for creating a track when a github account
  498. // connection has started
  499. type GithubConnectionStartTrackOpts struct {
  500. // note that this is a user-scoped track, since github repos are tied to the user
  501. *UserScopedTrackOpts
  502. }
  503. // GithubConnectionStartTrack returns a new track for when a github account
  504. // connection has started
  505. func GithubConnectionStartTrack(opts *GithubConnectionStartTrackOpts) segmentTrack {
  506. additionalProps := make(map[string]interface{})
  507. return getSegmentUserTrack(
  508. opts.UserScopedTrackOpts,
  509. getDefaultSegmentTrack(additionalProps, GithubConnectionStart),
  510. )
  511. }
  512. // GithubConnectionSuccessTrackOpts are the options for creating a track when a github account
  513. // connection has completed
  514. type GithubConnectionSuccessTrackOpts struct {
  515. // note that this is a user-scoped track, since github repos are tied to the user
  516. *UserScopedTrackOpts
  517. }
  518. // GithubConnectionSuccessTrack returns a new track when a github account
  519. // connection has completed
  520. func GithubConnectionSuccessTrack(opts *GithubConnectionSuccessTrackOpts) segmentTrack {
  521. additionalProps := make(map[string]interface{})
  522. return getSegmentUserTrack(
  523. opts.UserScopedTrackOpts,
  524. getDefaultSegmentTrack(additionalProps, GithubConnectionSuccess),
  525. )
  526. }
  527. // ApplicationLaunchStartTrackOpts are the options for creating a track when an application
  528. // launch has started
  529. type ApplicationLaunchStartTrackOpts struct {
  530. *ClusterScopedTrackOpts
  531. FlowID string
  532. }
  533. // ApplicationLaunchStartTrack returns a new track for when an application
  534. // launch has started
  535. func ApplicationLaunchStartTrack(opts *ApplicationLaunchStartTrackOpts) segmentTrack {
  536. additionalProps := make(map[string]interface{})
  537. additionalProps["flow_id"] = opts.FlowID
  538. return getSegmentClusterTrack(
  539. opts.ClusterScopedTrackOpts,
  540. getDefaultSegmentTrack(additionalProps, ApplicationLaunchStart),
  541. )
  542. }
  543. // ApplicationLaunchSuccessTrackOpts are the options for creating a track when an application
  544. // launch has completed
  545. type ApplicationLaunchSuccessTrackOpts struct {
  546. *ApplicationScopedTrackOpts
  547. FlowID string
  548. }
  549. // ApplicationLaunchSuccessTrack returns a new track for when an application
  550. // launch has completed
  551. func ApplicationLaunchSuccessTrack(opts *ApplicationLaunchSuccessTrackOpts) segmentTrack {
  552. additionalProps := make(map[string]interface{})
  553. additionalProps["flow_id"] = opts.FlowID
  554. return getSegmentApplicationTrack(
  555. opts.ApplicationScopedTrackOpts,
  556. getDefaultSegmentTrack(additionalProps, ApplicationLaunchSuccess),
  557. )
  558. }
  559. // ApplicationDeploymentWebhookTrackOpts are the options for creating a track when an application
  560. // launch has completed from a webhook
  561. type ApplicationDeploymentWebhookTrackOpts struct {
  562. *ApplicationScopedTrackOpts
  563. ImageURI string
  564. }
  565. // ApplicationDeploymentWebhookTrack returns a new track for when an application
  566. // launch has completed from a webhook
  567. func ApplicationDeploymentWebhookTrack(opts *ApplicationDeploymentWebhookTrackOpts) segmentTrack {
  568. additionalProps := make(map[string]interface{})
  569. additionalProps["image_uri"] = opts.ImageURI
  570. return getSegmentApplicationTrack(
  571. opts.ApplicationScopedTrackOpts,
  572. getDefaultSegmentTrack(additionalProps, ApplicationDeploymentWebhook),
  573. )
  574. }
  575. // RegistryProvisioningStartTrackOpts are the options for creating a track when a registry
  576. // provisioning has started
  577. type RegistryProvisioningStartTrackOpts struct {
  578. // note that this is a project-scoped track, since the registry has not been created yet
  579. *ProjectScopedTrackOpts
  580. RegistryType types.InfraKind
  581. InfraID uint
  582. }
  583. // RegistryProvisioningStartTrack returns a new track for when a registry
  584. // provisioning has started
  585. func RegistryProvisioningStartTrack(opts *RegistryProvisioningStartTrackOpts) segmentTrack {
  586. additionalProps := make(map[string]interface{})
  587. additionalProps["registry_type"] = opts.RegistryType
  588. additionalProps["infra_id"] = opts.InfraID
  589. return getSegmentProjectTrack(
  590. opts.ProjectScopedTrackOpts,
  591. getDefaultSegmentTrack(additionalProps, RegistryProvisioningStart),
  592. )
  593. }
  594. // RegistryProvisioningErrorTrackOpts are the options for creating a track when a registry
  595. // provisioning has failed
  596. type RegistryProvisioningErrorTrackOpts struct {
  597. // note that this is a project-scoped track, since the registry has not been created yet
  598. *ProjectScopedTrackOpts
  599. RegistryType types.InfraKind
  600. InfraID uint
  601. }
  602. // RegistryProvisioningErrorTrack returns a new track for when a registry
  603. // provisioning has failed
  604. func RegistryProvisioningErrorTrack(opts *RegistryProvisioningErrorTrackOpts) segmentTrack {
  605. additionalProps := make(map[string]interface{})
  606. additionalProps["registry_type"] = opts.RegistryType
  607. additionalProps["infra_id"] = opts.InfraID
  608. return getSegmentProjectTrack(
  609. opts.ProjectScopedTrackOpts,
  610. getDefaultSegmentTrack(additionalProps, RegistryProvisioningError),
  611. )
  612. }
  613. // RegistryProvisioningSuccessTrackOpts are the options for creating a track when a registry
  614. // provisioning has completed
  615. type RegistryProvisioningSuccessTrackOpts struct {
  616. *RegistryScopedTrackOpts
  617. RegistryType types.InfraKind
  618. InfraID uint
  619. }
  620. // RegistryProvisioningSuccessTrack returns a new track for when a registry
  621. // provisioning has completed
  622. func RegistryProvisioningSuccessTrack(opts *RegistryProvisioningSuccessTrackOpts) segmentTrack {
  623. additionalProps := make(map[string]interface{})
  624. additionalProps["registry_type"] = opts.RegistryType
  625. additionalProps["infra_id"] = opts.InfraID
  626. return getSegmentRegistryTrack(
  627. opts.RegistryScopedTrackOpts,
  628. getDefaultSegmentTrack(additionalProps, RegistryProvisioningSuccess),
  629. )
  630. }
  631. // ClusterDestroyingStartTrackOpts are the options for creating a track when a cluster
  632. // has started destroying
  633. type ClusterDestroyingStartTrackOpts struct {
  634. *ClusterScopedTrackOpts
  635. ClusterType types.InfraKind
  636. InfraID uint
  637. }
  638. // ClusterDestroyingStartTrack returns a track for when a cluster
  639. // has started destroying
  640. func ClusterDestroyingStartTrack(opts *ClusterDestroyingStartTrackOpts) segmentTrack {
  641. additionalProps := make(map[string]interface{})
  642. additionalProps["cluster_type"] = opts.ClusterType
  643. additionalProps["infra_id"] = opts.InfraID
  644. return getSegmentClusterTrack(
  645. opts.ClusterScopedTrackOpts,
  646. getDefaultSegmentTrack(additionalProps, ClusterDestroyingStart),
  647. )
  648. }
  649. // ClusterDestroyingSuccessTrackOpts are the options for creating a track when a cluster
  650. // has successfully provisioned
  651. type ClusterDestroyingSuccessTrackOpts struct {
  652. *ClusterScopedTrackOpts
  653. ClusterType types.InfraKind
  654. InfraID uint
  655. }
  656. // ClusterDestroyingSuccessTrack returns a new track for when a cluster
  657. // has successfully provisioned
  658. func ClusterDestroyingSuccessTrack(opts *ClusterDestroyingSuccessTrackOpts) segmentTrack {
  659. additionalProps := make(map[string]interface{})
  660. additionalProps["cluster_type"] = opts.ClusterType
  661. additionalProps["infra_id"] = opts.InfraID
  662. return getSegmentClusterTrack(
  663. opts.ClusterScopedTrackOpts,
  664. getDefaultSegmentTrack(additionalProps, ClusterDestroyingSuccess),
  665. )
  666. }
  667. // StackLaunchStartOpts are the options for creating a track when a user starts creating a stack
  668. type StackLaunchStartOpts struct {
  669. *ProjectScopedTrackOpts
  670. Email string
  671. FirstName string
  672. LastName string
  673. CompanyName string
  674. ValidateApplyV2 bool
  675. }
  676. // StackLaunchStartTrack returns a track for when a user starts creating a stack
  677. func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
  678. additionalProps := make(map[string]interface{})
  679. additionalProps["email"] = opts.Email
  680. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  681. additionalProps["company"] = opts.CompanyName
  682. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  683. return getSegmentProjectTrack(
  684. opts.ProjectScopedTrackOpts,
  685. getDefaultSegmentTrack(additionalProps, StackLaunchStart),
  686. )
  687. }
  688. // StackLaunchCompleteOpts are the options for creating a track when a user completes creating a stack
  689. type StackLaunchCompleteOpts struct {
  690. *ProjectScopedTrackOpts
  691. StackName string
  692. Email string
  693. FirstName string
  694. LastName string
  695. CompanyName string
  696. ValidateApplyV2 bool
  697. }
  698. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  699. func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
  700. additionalProps := make(map[string]interface{})
  701. additionalProps["stack_name"] = opts.StackName
  702. additionalProps["email"] = opts.Email
  703. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  704. additionalProps["company"] = opts.CompanyName
  705. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  706. return getSegmentProjectTrack(
  707. opts.ProjectScopedTrackOpts,
  708. getDefaultSegmentTrack(additionalProps, StackLaunchComplete),
  709. )
  710. }
  711. // StackLaunchSuccessOpts are the options for creating a track when a user succeeds in creating a stack
  712. type StackLaunchSuccessOpts struct {
  713. *ProjectScopedTrackOpts
  714. StackName string
  715. Email string
  716. FirstName string
  717. LastName string
  718. CompanyName string
  719. ValidateApplyV2 bool
  720. }
  721. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  722. func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
  723. additionalProps := make(map[string]interface{})
  724. additionalProps["stack_name"] = opts.StackName
  725. additionalProps["email"] = opts.Email
  726. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  727. additionalProps["company"] = opts.CompanyName
  728. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  729. return getSegmentProjectTrack(
  730. opts.ProjectScopedTrackOpts,
  731. getDefaultSegmentTrack(additionalProps, StackLaunchSuccess),
  732. )
  733. }
  734. // StackLaunchFailureOpts are the options for creating a track when a user fails in creating a stack
  735. type StackLaunchFailureOpts struct {
  736. *ProjectScopedTrackOpts
  737. StackName string
  738. Email string
  739. FirstName string
  740. LastName string
  741. CompanyName string
  742. ErrorMessage string
  743. ValidateApplyV2 bool
  744. }
  745. // StackLaunchFailureTrack returns a track for when a user fails creating a stack
  746. func StackLaunchFailureTrack(opts *StackLaunchFailureOpts) segmentTrack {
  747. additionalProps := make(map[string]interface{})
  748. additionalProps["stack_name"] = opts.StackName
  749. additionalProps["email"] = opts.Email
  750. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  751. additionalProps["company"] = opts.CompanyName
  752. additionalProps["error_message"] = opts.ErrorMessage
  753. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  754. return getSegmentProjectTrack(
  755. opts.ProjectScopedTrackOpts,
  756. getDefaultSegmentTrack(additionalProps, StackLaunchFailure),
  757. )
  758. }
  759. // StackDeletionOpts are the options for creating a track when a user deletes a stack
  760. type StackDeletionOpts struct {
  761. *ProjectScopedTrackOpts
  762. StackName string
  763. Email string
  764. FirstName string
  765. LastName string
  766. CompanyName string
  767. DeleteWorkflowFile bool
  768. ValidateApplyV2 bool
  769. }
  770. // StackDeletionTrack returns a track for when a user deletes a stack
  771. func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
  772. additionalProps := make(map[string]interface{})
  773. additionalProps["stack_name"] = opts.StackName
  774. additionalProps["email"] = opts.Email
  775. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  776. additionalProps["company"] = opts.CompanyName
  777. additionalProps["delete_workflow_file"] = opts.DeleteWorkflowFile
  778. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  779. return getSegmentProjectTrack(
  780. opts.ProjectScopedTrackOpts,
  781. getDefaultSegmentTrack(additionalProps, StackDeletion),
  782. )
  783. }
  784. // StackBuildOpts are the options for creating a track when a stack builds
  785. type StackBuildOpts struct {
  786. *ProjectScopedTrackOpts
  787. StackName string
  788. ErrorMessage string
  789. B64BuildLogs string
  790. Email string
  791. FirstName string
  792. LastName string
  793. CompanyName string
  794. ValidateApplyV2 bool
  795. }
  796. // StackBuildFailureTrack returns a track for when a stack fails to build
  797. func StackBuildFailureTrack(opts *StackBuildOpts) segmentTrack {
  798. additionalProps := make(map[string]interface{})
  799. additionalProps["stack_name"] = opts.StackName
  800. additionalProps["error_message"] = opts.ErrorMessage
  801. additionalProps["email"] = opts.Email
  802. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  803. additionalProps["company"] = opts.CompanyName
  804. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  805. additionalProps["b64_build_logs"] = opts.B64BuildLogs
  806. return getSegmentProjectTrack(
  807. opts.ProjectScopedTrackOpts,
  808. getDefaultSegmentTrack(additionalProps, StackBuildFailure),
  809. )
  810. }
  811. // StackBuildSuccessTrack returns a track for when a stack succeeds to build
  812. func StackBuildSuccessTrack(opts *StackBuildOpts) segmentTrack {
  813. additionalProps := make(map[string]interface{})
  814. additionalProps["stack_name"] = opts.StackName
  815. additionalProps["email"] = opts.Email
  816. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  817. additionalProps["company"] = opts.CompanyName
  818. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  819. return getSegmentProjectTrack(
  820. opts.ProjectScopedTrackOpts,
  821. getDefaultSegmentTrack(additionalProps, StackBuildSuccess),
  822. )
  823. }
  824. // StackBuildProgressingTrack returns a track for when a stack starts to build
  825. func StackBuildProgressingTrack(opts *StackBuildOpts) segmentTrack {
  826. additionalProps := make(map[string]interface{})
  827. additionalProps["stack_name"] = opts.StackName
  828. additionalProps["email"] = opts.Email
  829. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  830. additionalProps["company"] = opts.CompanyName
  831. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  832. return getSegmentProjectTrack(
  833. opts.ProjectScopedTrackOpts,
  834. getDefaultSegmentTrack(additionalProps, StackBuildProgressing),
  835. )
  836. }
  837. // PorterAppUpdateOpts are the options for creating a track when a user updates a porter app
  838. type PorterAppUpdateOpts struct {
  839. *ProjectScopedTrackOpts
  840. StackName string
  841. Email string
  842. FirstName string
  843. LastName string
  844. CompanyName string
  845. ErrorMessage string
  846. ErrorStackTrace string
  847. ValidateApplyV2 bool
  848. }
  849. // PorterAppUpdateFailureTrack returns a track for when a user attempts to update an app and receives an error
  850. func PorterAppUpdateFailureTrack(opts *PorterAppUpdateOpts) segmentTrack {
  851. additionalProps := make(map[string]interface{})
  852. additionalProps["stack_name"] = opts.StackName
  853. additionalProps["email"] = opts.Email
  854. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  855. additionalProps["company"] = opts.CompanyName
  856. additionalProps["error_message"] = opts.ErrorMessage
  857. additionalProps["error_stack_trace"] = opts.ErrorStackTrace
  858. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  859. return getSegmentProjectTrack(
  860. opts.ProjectScopedTrackOpts,
  861. getDefaultSegmentTrack(additionalProps, PorterAppUpdateFailure),
  862. )
  863. }
  864. // CloudProviderPermissionsGrantedTrackOpts are the options for creating a track when a user grants permission to use porter
  865. type CloudProviderPermissionsGrantedTrackOpts struct {
  866. *ProjectScopedTrackOpts
  867. Email string
  868. FirstName string
  869. LastName string
  870. CompanyName string
  871. CloudProvider string
  872. CloudProviderCredentialIdentifier string
  873. }
  874. // CloudProviderPermissionsGrantedTrack returns a track for when a user grants permission to use porter
  875. func CloudProviderPermissionsGrantedTrack(opts *CloudProviderPermissionsGrantedTrackOpts) segmentTrack {
  876. additionalProps := make(map[string]interface{})
  877. additionalProps["email"] = opts.Email
  878. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  879. additionalProps["company"] = opts.CompanyName
  880. additionalProps["cloud_provider"] = opts.CloudProvider
  881. additionalProps["cloud_provider_credential_identifier"] = opts.CloudProviderCredentialIdentifier
  882. return getSegmentProjectTrack(
  883. opts.ProjectScopedTrackOpts,
  884. getDefaultSegmentTrack(additionalProps, CloudProviderPermissionsGranted),
  885. )
  886. }
  887. // ClusterPreflightChecksFailedTrackOpts are the options for creating a track when a user fails preflight checks
  888. type ClusterPreflightChecksFailedTrackOpts struct {
  889. *ProjectScopedTrackOpts
  890. Email string
  891. FirstName string
  892. LastName string
  893. CompanyName string
  894. ErrorMessage string
  895. }
  896. // ClusterPreflightChecksFailedTrack returns a track for when a user fails preflight checks
  897. func ClusterPreflightChecksFailedTrack(opts *ClusterPreflightChecksFailedTrackOpts) segmentTrack {
  898. additionalProps := make(map[string]interface{})
  899. additionalProps["email"] = opts.Email
  900. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  901. additionalProps["company"] = opts.CompanyName
  902. additionalProps["error_message"] = opts.ErrorMessage
  903. return getSegmentProjectTrack(
  904. opts.ProjectScopedTrackOpts,
  905. getDefaultSegmentTrack(additionalProps, ClusterPreflightChecksFailed),
  906. )
  907. }
  908. // ClusterUpdateFailedTrackOpts are the options for creating a track when a user fails to update a cluster
  909. type ClusterUpdateFailedTrackOpts struct {
  910. *ProjectScopedTrackOpts
  911. ClusterName string
  912. Email string
  913. FirstName string
  914. LastName string
  915. CompanyName string
  916. ErrorMessage string
  917. }
  918. // ClusterUpdateFailedTrack returns a track for when a user fails to update a cluster
  919. func ClusterUpdateFailedTrack(opts *ClusterUpdateFailedTrackOpts) segmentTrack {
  920. additionalProps := make(map[string]interface{})
  921. additionalProps["cluster_name"] = opts.ClusterName
  922. additionalProps["email"] = opts.Email
  923. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  924. additionalProps["company"] = opts.CompanyName
  925. additionalProps["error_message"] = opts.ErrorMessage
  926. return getSegmentProjectTrack(
  927. opts.ProjectScopedTrackOpts,
  928. getDefaultSegmentTrack(additionalProps, ClusterUpdateFailed),
  929. )
  930. }