tracks.go 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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. // ProjectCreateTrack returns a track for when a project is created
  104. func ProjectCreateTrack(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, ProjectCreate),
  112. )
  113. }
  114. // ProjectDeleteTrack returns a track for when a project is deleted
  115. func ProjectDeleteTrack(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, ProjectDelete),
  123. )
  124. }
  125. // ClusterDeleteTrackOpts are the options for creating a track when a cluster is deleted
  126. type ClusterDeleteTrackOpts struct {
  127. *ProjectScopedTrackOpts
  128. Email string
  129. FirstName string
  130. LastName string
  131. CompanyName string
  132. }
  133. // ClusterDeleteTrack returns a track for when a cluster is deleted
  134. func ClusterDeleteTrack(opts *ClusterDeleteTrackOpts) segmentTrack {
  135. additionalProps := make(map[string]interface{})
  136. additionalProps["email"] = opts.Email
  137. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  138. additionalProps["company"] = opts.CompanyName
  139. return getSegmentProjectTrack(
  140. opts.ProjectScopedTrackOpts,
  141. getDefaultSegmentTrack(additionalProps, ClusterDelete),
  142. )
  143. }
  144. // CostConsentOpenedTrackOpts are the options for creating a track when a user opens the cost consent
  145. type CostConsentOpenedTrackOpts struct {
  146. *UserScopedTrackOpts
  147. Provider string
  148. Email string
  149. FirstName string
  150. LastName string
  151. CompanyName string
  152. }
  153. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  154. func CostConsentOpenedTrack(opts *CostConsentOpenedTrackOpts) segmentTrack {
  155. additionalProps := make(map[string]interface{})
  156. additionalProps["provider"] = opts.Provider
  157. additionalProps["email"] = opts.Email
  158. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  159. additionalProps["company"] = opts.CompanyName
  160. return getSegmentUserTrack(
  161. opts.UserScopedTrackOpts,
  162. getDefaultSegmentTrack(additionalProps, CostConsentOpened),
  163. )
  164. }
  165. // CostConsentCompletedTrackOpts are the options for creating a track when a user completes the cost consent
  166. type CostConsentCompletedTrackOpts struct {
  167. *UserScopedTrackOpts
  168. Provider string
  169. Email string
  170. FirstName string
  171. LastName string
  172. CompanyName string
  173. }
  174. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  175. func CostConsentCompletedTrack(opts *CostConsentCompletedTrackOpts) segmentTrack {
  176. additionalProps := make(map[string]interface{})
  177. additionalProps["provider"] = opts.Provider
  178. additionalProps["email"] = opts.Email
  179. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  180. additionalProps["company"] = opts.CompanyName
  181. return getSegmentUserTrack(
  182. opts.UserScopedTrackOpts,
  183. getDefaultSegmentTrack(additionalProps, CostConsentComplete),
  184. )
  185. }
  186. // AWSInputTrackOpts are the options for creating a track when a user inputs a complete AWS account ID
  187. type AWSInputTrackOpts struct {
  188. *ProjectScopedTrackOpts
  189. Email string
  190. FirstName string
  191. LastName string
  192. CompanyName string
  193. AccountId string
  194. }
  195. // AWSInputTrack returns a track for when a user inputs a complete AWS account ID
  196. func AWSInputTrack(opts *AWSInputTrackOpts) segmentTrack {
  197. additionalProps := make(map[string]interface{})
  198. additionalProps["email"] = opts.Email
  199. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  200. additionalProps["company"] = opts.CompanyName
  201. additionalProps["account_id"] = opts.AccountId
  202. return getSegmentProjectTrack(
  203. opts.ProjectScopedTrackOpts,
  204. getDefaultSegmentTrack(additionalProps, AWSInputted),
  205. )
  206. }
  207. type AWSRedirectOpts struct {
  208. *ProjectScopedTrackOpts
  209. Email string
  210. FirstName string
  211. LastName string
  212. CompanyName string
  213. AccountId string
  214. CloudformationURL string
  215. LoginURL string
  216. ExternalId string
  217. }
  218. // AWSCloudformationRedirectSuccess returns a track for when a user clicks 'grant permissions' and gets redirected to cloudformation
  219. func AWSCloudformationRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  220. additionalProps := make(map[string]interface{})
  221. additionalProps["email"] = opts.Email
  222. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  223. additionalProps["company"] = opts.CompanyName
  224. additionalProps["account_id"] = opts.AccountId
  225. additionalProps["cloudformation_url"] = opts.CloudformationURL
  226. additionalProps["external_id"] = opts.ExternalId
  227. return getSegmentProjectTrack(
  228. opts.ProjectScopedTrackOpts,
  229. getDefaultSegmentTrack(additionalProps, AWSCloudformationRedirect),
  230. )
  231. }
  232. // AWSLoginRedirectSuccess returns a track for when a user is prompted to login to AWS
  233. func AWSLoginRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  234. additionalProps := make(map[string]interface{})
  235. additionalProps["email"] = opts.Email
  236. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  237. additionalProps["company"] = opts.CompanyName
  238. additionalProps["account_id"] = opts.AccountId
  239. additionalProps["login_url"] = opts.LoginURL
  240. return getSegmentProjectTrack(
  241. opts.ProjectScopedTrackOpts,
  242. getDefaultSegmentTrack(additionalProps, AWSLoginRedirect),
  243. )
  244. }
  245. type AWSCreateIntegrationOpts struct {
  246. *ProjectScopedTrackOpts
  247. Email string
  248. FirstName string
  249. LastName string
  250. CompanyName string
  251. AccountId string
  252. ExternalId string
  253. ErrorMessage string
  254. }
  255. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  256. func AWSCreateIntegrationSucceeded(opts *AWSCreateIntegrationOpts) segmentTrack {
  257. additionalProps := make(map[string]interface{})
  258. additionalProps["email"] = opts.Email
  259. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  260. additionalProps["company"] = opts.CompanyName
  261. additionalProps["account_id"] = opts.AccountId
  262. return getSegmentProjectTrack(
  263. opts.ProjectScopedTrackOpts,
  264. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationSuccess),
  265. )
  266. }
  267. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  268. func AWSCreateIntegrationFailed(opts *AWSCreateIntegrationOpts) segmentTrack {
  269. additionalProps := make(map[string]interface{})
  270. additionalProps["email"] = opts.Email
  271. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  272. additionalProps["company"] = opts.CompanyName
  273. additionalProps["account_id"] = opts.AccountId
  274. additionalProps["error_message"] = opts.ErrorMessage
  275. additionalProps["external_id"] = opts.ExternalId
  276. return getSegmentProjectTrack(
  277. opts.ProjectScopedTrackOpts,
  278. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationFailure),
  279. )
  280. }
  281. // CredentialStepTrackOpts are the options for creating a track when a user completes the credential step
  282. type CredentialStepTrackOpts struct {
  283. *UserScopedTrackOpts
  284. }
  285. // CredentialStepTrack returns a track for when a user completes the credential step
  286. func CredentialStepTrack(opts *CredentialStepTrackOpts) segmentTrack {
  287. additionalProps := make(map[string]interface{})
  288. return getSegmentUserTrack(
  289. opts.UserScopedTrackOpts,
  290. getDefaultSegmentTrack(additionalProps, CredentialStepComplete),
  291. )
  292. }
  293. // PreProvisionCheckTrackOpts are the options for creating a track when a user checks if they can provision
  294. type PreProvisionCheckTrackOpts struct {
  295. *ProjectScopedTrackOpts
  296. Email string
  297. FirstName string
  298. LastName string
  299. CompanyName string
  300. }
  301. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  302. func PreProvisionCheckTrack(opts *PreProvisionCheckTrackOpts) segmentTrack {
  303. additionalProps := make(map[string]interface{})
  304. additionalProps["email"] = opts.Email
  305. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  306. additionalProps["company"] = opts.CompanyName
  307. return getSegmentProjectTrack(
  308. opts.ProjectScopedTrackOpts,
  309. getDefaultSegmentTrack(additionalProps, PreProvisionCheck),
  310. )
  311. }
  312. // ProvisioningAttemptedTrackOpts are the options for creating a track when a user attempts provisioning
  313. type ProvisioningAttemptTrackOpts struct {
  314. *ProjectScopedTrackOpts
  315. Email string
  316. FirstName string
  317. LastName string
  318. CompanyName string
  319. ErrorMessage string
  320. Region string
  321. Provider string
  322. }
  323. // ProvisioningAttemptTrack returns a track for when a user attempts provisioning
  324. func ProvisioningAttemptTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  325. additionalProps := make(map[string]interface{})
  326. additionalProps["email"] = opts.Email
  327. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  328. additionalProps["company"] = opts.CompanyName
  329. additionalProps["region"] = opts.Region
  330. additionalProps["provider"] = opts.Provider
  331. return getSegmentProjectTrack(
  332. opts.ProjectScopedTrackOpts,
  333. getDefaultSegmentTrack(additionalProps, ProvisioningAttempted),
  334. )
  335. }
  336. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  337. func ProvisionFailureTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  338. additionalProps := make(map[string]interface{})
  339. additionalProps["email"] = opts.Email
  340. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  341. additionalProps["company"] = opts.CompanyName
  342. additionalProps["error_message"] = opts.ErrorMessage
  343. additionalProps["region"] = opts.Region
  344. return getSegmentProjectTrack(
  345. opts.ProjectScopedTrackOpts,
  346. getDefaultSegmentTrack(additionalProps, ProvisioningFailure),
  347. )
  348. }
  349. // ClusterProvisioningStartTrackOpts are the options for creating a track when a cluster
  350. // has started provisioning
  351. type ClusterProvisioningStartTrackOpts struct {
  352. // note that this is a project-scoped track, since the cluster has not been created yet
  353. *ProjectScopedTrackOpts
  354. ClusterType types.InfraKind
  355. InfraID uint
  356. }
  357. // ClusterProvisioningStartTrack returns a track for when a cluster
  358. // has started provisioning
  359. func ClusterProvisioningStartTrack(opts *ClusterProvisioningStartTrackOpts) segmentTrack {
  360. additionalProps := make(map[string]interface{})
  361. additionalProps["cluster_type"] = opts.ClusterType
  362. additionalProps["infra_id"] = opts.InfraID
  363. return getSegmentProjectTrack(
  364. opts.ProjectScopedTrackOpts,
  365. getDefaultSegmentTrack(additionalProps, ClusterProvisioningStart),
  366. )
  367. }
  368. // ClusterProvisioningErrorTrackOpts are the options for creating a track when a cluster
  369. // has experienced a provisioning error
  370. type ClusterProvisioningErrorTrackOpts struct {
  371. // note that this is a project-scoped track, since the cluster has not been created yet
  372. *ProjectScopedTrackOpts
  373. ClusterType types.InfraKind
  374. InfraID uint
  375. }
  376. // ClusterProvisioningErrorTrack returns a track for when a cluster
  377. // has experienced a provisioning error
  378. func ClusterProvisioningErrorTrack(opts *ClusterProvisioningErrorTrackOpts) segmentTrack {
  379. additionalProps := make(map[string]interface{})
  380. additionalProps["cluster_type"] = opts.ClusterType
  381. additionalProps["infra_id"] = opts.InfraID
  382. return getSegmentProjectTrack(
  383. opts.ProjectScopedTrackOpts,
  384. getDefaultSegmentTrack(additionalProps, ClusterProvisioningError),
  385. )
  386. }
  387. // ClusterProvisioningSuccessTrackOpts are the options for creating a track when a cluster
  388. // has successfully provisioned
  389. type ClusterProvisioningSuccessTrackOpts struct {
  390. *ClusterScopedTrackOpts
  391. ClusterType types.InfraKind
  392. InfraID uint
  393. }
  394. // ClusterProvisioningSuccessTrack returns a new track for when a cluster
  395. // has successfully provisioned
  396. func ClusterProvisioningSuccessTrack(opts *ClusterProvisioningSuccessTrackOpts) segmentTrack {
  397. additionalProps := make(map[string]interface{})
  398. additionalProps["cluster_type"] = opts.ClusterType
  399. additionalProps["infra_id"] = opts.InfraID
  400. return getSegmentClusterTrack(
  401. opts.ClusterScopedTrackOpts,
  402. getDefaultSegmentTrack(additionalProps, ClusterProvisioningSuccess),
  403. )
  404. }
  405. // ClusterConnectionStartTrackOpts are the options for creating a track when a cluster
  406. // connection has started
  407. type ClusterConnectionStartTrackOpts struct {
  408. // note that this is a project-scoped track, since the cluster has not been created yet
  409. *ProjectScopedTrackOpts
  410. ClusterCandidateID uint
  411. }
  412. // ClusterConnectionStartTrack returns a new track for when a cluster
  413. // connection has started
  414. func ClusterConnectionStartTrack(opts *ClusterConnectionStartTrackOpts) segmentTrack {
  415. additionalProps := make(map[string]interface{})
  416. additionalProps["cc_id"] = opts.ClusterCandidateID
  417. return getSegmentProjectTrack(
  418. opts.ProjectScopedTrackOpts,
  419. getDefaultSegmentTrack(additionalProps, ClusterConnectionStart),
  420. )
  421. }
  422. // ClusterConnectionSuccessTrackOpts are the options for creating a track when a cluster
  423. // connection has finished
  424. type ClusterConnectionSuccessTrackOpts struct {
  425. *ClusterScopedTrackOpts
  426. ClusterCandidateID uint
  427. }
  428. // ClusterConnectionSuccessTrack returns a new track for when a cluster
  429. // connection has finished
  430. func ClusterConnectionSuccessTrack(opts *ClusterConnectionSuccessTrackOpts) segmentTrack {
  431. additionalProps := make(map[string]interface{})
  432. additionalProps["cc_id"] = opts.ClusterCandidateID
  433. return getSegmentClusterTrack(
  434. opts.ClusterScopedTrackOpts,
  435. getDefaultSegmentTrack(additionalProps, ClusterConnectionSuccess),
  436. )
  437. }
  438. // RegistryConnectionStartTrackOpts are the options for creating a track when a registry
  439. // connection has started
  440. type RegistryConnectionStartTrackOpts struct {
  441. // note that this is a project-scoped track, since the cluster has not been created yet
  442. *ProjectScopedTrackOpts
  443. // a random id assigned to this connection request
  444. FlowID string
  445. }
  446. // RegistryConnectionStartTrack returns a new track for when a registry
  447. // connection has started
  448. func RegistryConnectionStartTrack(opts *RegistryConnectionStartTrackOpts) segmentTrack {
  449. additionalProps := make(map[string]interface{})
  450. additionalProps["flow_id"] = opts.FlowID
  451. return getSegmentProjectTrack(
  452. opts.ProjectScopedTrackOpts,
  453. getDefaultSegmentTrack(additionalProps, RegistryConnectionStart),
  454. )
  455. }
  456. // RegistryConnectionSuccessTrackOpts are the options for creating a track when a registry
  457. // connection has completed
  458. type RegistryConnectionSuccessTrackOpts struct {
  459. *RegistryScopedTrackOpts
  460. // a random id assigned to this connection request
  461. FlowID string
  462. }
  463. // RegistryConnectionSuccessTrack returns a new track for when a registry
  464. // connection has completed
  465. func RegistryConnectionSuccessTrack(opts *RegistryConnectionSuccessTrackOpts) segmentTrack {
  466. additionalProps := make(map[string]interface{})
  467. additionalProps["flow_id"] = opts.FlowID
  468. return getSegmentRegistryTrack(
  469. opts.RegistryScopedTrackOpts,
  470. getDefaultSegmentTrack(additionalProps, RegistryConnectionSuccess),
  471. )
  472. }
  473. // GithubConnectionStartTrackOpts are the options for creating a track when a github account
  474. // connection has started
  475. type GithubConnectionStartTrackOpts struct {
  476. // note that this is a user-scoped track, since github repos are tied to the user
  477. *UserScopedTrackOpts
  478. }
  479. // GithubConnectionStartTrack returns a new track for when a github account
  480. // connection has started
  481. func GithubConnectionStartTrack(opts *GithubConnectionStartTrackOpts) segmentTrack {
  482. additionalProps := make(map[string]interface{})
  483. return getSegmentUserTrack(
  484. opts.UserScopedTrackOpts,
  485. getDefaultSegmentTrack(additionalProps, GithubConnectionStart),
  486. )
  487. }
  488. // GithubConnectionSuccessTrackOpts are the options for creating a track when a github account
  489. // connection has completed
  490. type GithubConnectionSuccessTrackOpts struct {
  491. // note that this is a user-scoped track, since github repos are tied to the user
  492. *UserScopedTrackOpts
  493. }
  494. // GithubConnectionSuccessTrack returns a new track when a github account
  495. // connection has completed
  496. func GithubConnectionSuccessTrack(opts *GithubConnectionSuccessTrackOpts) segmentTrack {
  497. additionalProps := make(map[string]interface{})
  498. return getSegmentUserTrack(
  499. opts.UserScopedTrackOpts,
  500. getDefaultSegmentTrack(additionalProps, GithubConnectionSuccess),
  501. )
  502. }
  503. // ApplicationLaunchStartTrackOpts are the options for creating a track when an application
  504. // launch has started
  505. type ApplicationLaunchStartTrackOpts struct {
  506. *ClusterScopedTrackOpts
  507. FlowID string
  508. }
  509. // ApplicationLaunchStartTrack returns a new track for when an application
  510. // launch has started
  511. func ApplicationLaunchStartTrack(opts *ApplicationLaunchStartTrackOpts) segmentTrack {
  512. additionalProps := make(map[string]interface{})
  513. additionalProps["flow_id"] = opts.FlowID
  514. return getSegmentClusterTrack(
  515. opts.ClusterScopedTrackOpts,
  516. getDefaultSegmentTrack(additionalProps, ApplicationLaunchStart),
  517. )
  518. }
  519. // ApplicationLaunchSuccessTrackOpts are the options for creating a track when an application
  520. // launch has completed
  521. type ApplicationLaunchSuccessTrackOpts struct {
  522. *ApplicationScopedTrackOpts
  523. FlowID string
  524. }
  525. // ApplicationLaunchSuccessTrack returns a new track for when an application
  526. // launch has completed
  527. func ApplicationLaunchSuccessTrack(opts *ApplicationLaunchSuccessTrackOpts) segmentTrack {
  528. additionalProps := make(map[string]interface{})
  529. additionalProps["flow_id"] = opts.FlowID
  530. return getSegmentApplicationTrack(
  531. opts.ApplicationScopedTrackOpts,
  532. getDefaultSegmentTrack(additionalProps, ApplicationLaunchSuccess),
  533. )
  534. }
  535. // ApplicationDeploymentWebhookTrackOpts are the options for creating a track when an application
  536. // launch has completed from a webhook
  537. type ApplicationDeploymentWebhookTrackOpts struct {
  538. *ApplicationScopedTrackOpts
  539. ImageURI string
  540. }
  541. // ApplicationDeploymentWebhookTrack returns a new track for when an application
  542. // launch has completed from a webhook
  543. func ApplicationDeploymentWebhookTrack(opts *ApplicationDeploymentWebhookTrackOpts) segmentTrack {
  544. additionalProps := make(map[string]interface{})
  545. additionalProps["image_uri"] = opts.ImageURI
  546. return getSegmentApplicationTrack(
  547. opts.ApplicationScopedTrackOpts,
  548. getDefaultSegmentTrack(additionalProps, ApplicationDeploymentWebhook),
  549. )
  550. }
  551. // RegistryProvisioningStartTrackOpts are the options for creating a track when a registry
  552. // provisioning has started
  553. type RegistryProvisioningStartTrackOpts struct {
  554. // note that this is a project-scoped track, since the registry has not been created yet
  555. *ProjectScopedTrackOpts
  556. RegistryType types.InfraKind
  557. InfraID uint
  558. }
  559. // RegistryProvisioningStartTrack returns a new track for when a registry
  560. // provisioning has started
  561. func RegistryProvisioningStartTrack(opts *RegistryProvisioningStartTrackOpts) segmentTrack {
  562. additionalProps := make(map[string]interface{})
  563. additionalProps["registry_type"] = opts.RegistryType
  564. additionalProps["infra_id"] = opts.InfraID
  565. return getSegmentProjectTrack(
  566. opts.ProjectScopedTrackOpts,
  567. getDefaultSegmentTrack(additionalProps, RegistryProvisioningStart),
  568. )
  569. }
  570. // RegistryProvisioningErrorTrackOpts are the options for creating a track when a registry
  571. // provisioning has failed
  572. type RegistryProvisioningErrorTrackOpts struct {
  573. // note that this is a project-scoped track, since the registry has not been created yet
  574. *ProjectScopedTrackOpts
  575. RegistryType types.InfraKind
  576. InfraID uint
  577. }
  578. // RegistryProvisioningErrorTrack returns a new track for when a registry
  579. // provisioning has failed
  580. func RegistryProvisioningErrorTrack(opts *RegistryProvisioningErrorTrackOpts) segmentTrack {
  581. additionalProps := make(map[string]interface{})
  582. additionalProps["registry_type"] = opts.RegistryType
  583. additionalProps["infra_id"] = opts.InfraID
  584. return getSegmentProjectTrack(
  585. opts.ProjectScopedTrackOpts,
  586. getDefaultSegmentTrack(additionalProps, RegistryProvisioningError),
  587. )
  588. }
  589. // RegistryProvisioningSuccessTrackOpts are the options for creating a track when a registry
  590. // provisioning has completed
  591. type RegistryProvisioningSuccessTrackOpts struct {
  592. *RegistryScopedTrackOpts
  593. RegistryType types.InfraKind
  594. InfraID uint
  595. }
  596. // RegistryProvisioningSuccessTrack returns a new track for when a registry
  597. // provisioning has completed
  598. func RegistryProvisioningSuccessTrack(opts *RegistryProvisioningSuccessTrackOpts) segmentTrack {
  599. additionalProps := make(map[string]interface{})
  600. additionalProps["registry_type"] = opts.RegistryType
  601. additionalProps["infra_id"] = opts.InfraID
  602. return getSegmentRegistryTrack(
  603. opts.RegistryScopedTrackOpts,
  604. getDefaultSegmentTrack(additionalProps, RegistryProvisioningSuccess),
  605. )
  606. }
  607. // ClusterDestroyingStartTrackOpts are the options for creating a track when a cluster
  608. // has started destroying
  609. type ClusterDestroyingStartTrackOpts struct {
  610. *ClusterScopedTrackOpts
  611. ClusterType types.InfraKind
  612. InfraID uint
  613. }
  614. // ClusterDestroyingStartTrack returns a track for when a cluster
  615. // has started destroying
  616. func ClusterDestroyingStartTrack(opts *ClusterDestroyingStartTrackOpts) segmentTrack {
  617. additionalProps := make(map[string]interface{})
  618. additionalProps["cluster_type"] = opts.ClusterType
  619. additionalProps["infra_id"] = opts.InfraID
  620. return getSegmentClusterTrack(
  621. opts.ClusterScopedTrackOpts,
  622. getDefaultSegmentTrack(additionalProps, ClusterDestroyingStart),
  623. )
  624. }
  625. // ClusterDestroyingSuccessTrackOpts are the options for creating a track when a cluster
  626. // has successfully provisioned
  627. type ClusterDestroyingSuccessTrackOpts struct {
  628. *ClusterScopedTrackOpts
  629. ClusterType types.InfraKind
  630. InfraID uint
  631. }
  632. // ClusterDestroyingSuccessTrack returns a new track for when a cluster
  633. // has successfully provisioned
  634. func ClusterDestroyingSuccessTrack(opts *ClusterDestroyingSuccessTrackOpts) segmentTrack {
  635. additionalProps := make(map[string]interface{})
  636. additionalProps["cluster_type"] = opts.ClusterType
  637. additionalProps["infra_id"] = opts.InfraID
  638. return getSegmentClusterTrack(
  639. opts.ClusterScopedTrackOpts,
  640. getDefaultSegmentTrack(additionalProps, ClusterDestroyingSuccess),
  641. )
  642. }
  643. // StackLaunchStartOpts are the options for creating a track when a user starts creating a stack
  644. type StackLaunchStartOpts struct {
  645. *ProjectScopedTrackOpts
  646. Email string
  647. FirstName string
  648. LastName string
  649. CompanyName string
  650. ValidateApplyV2 bool
  651. }
  652. // StackLaunchStartTrack returns a track for when a user starts creating a stack
  653. func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
  654. additionalProps := make(map[string]interface{})
  655. additionalProps["email"] = opts.Email
  656. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  657. additionalProps["company"] = opts.CompanyName
  658. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  659. return getSegmentProjectTrack(
  660. opts.ProjectScopedTrackOpts,
  661. getDefaultSegmentTrack(additionalProps, StackLaunchStart),
  662. )
  663. }
  664. // StackLaunchCompleteOpts are the options for creating a track when a user completes creating a stack
  665. type StackLaunchCompleteOpts struct {
  666. *ProjectScopedTrackOpts
  667. StackName string
  668. Email string
  669. FirstName string
  670. LastName string
  671. CompanyName string
  672. ValidateApplyV2 bool
  673. }
  674. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  675. func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
  676. additionalProps := make(map[string]interface{})
  677. additionalProps["stack_name"] = opts.StackName
  678. additionalProps["email"] = opts.Email
  679. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  680. additionalProps["company"] = opts.CompanyName
  681. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  682. return getSegmentProjectTrack(
  683. opts.ProjectScopedTrackOpts,
  684. getDefaultSegmentTrack(additionalProps, StackLaunchComplete),
  685. )
  686. }
  687. // StackLaunchSuccessOpts are the options for creating a track when a user succeeds in creating a stack
  688. type StackLaunchSuccessOpts struct {
  689. *ProjectScopedTrackOpts
  690. StackName string
  691. Email string
  692. FirstName string
  693. LastName string
  694. CompanyName string
  695. ValidateApplyV2 bool
  696. }
  697. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  698. func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
  699. additionalProps := make(map[string]interface{})
  700. additionalProps["stack_name"] = opts.StackName
  701. additionalProps["email"] = opts.Email
  702. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  703. additionalProps["company"] = opts.CompanyName
  704. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  705. return getSegmentProjectTrack(
  706. opts.ProjectScopedTrackOpts,
  707. getDefaultSegmentTrack(additionalProps, StackLaunchSuccess),
  708. )
  709. }
  710. // StackLaunchFailureOpts are the options for creating a track when a user fails in creating a stack
  711. type StackLaunchFailureOpts struct {
  712. *ProjectScopedTrackOpts
  713. StackName string
  714. Email string
  715. FirstName string
  716. LastName string
  717. CompanyName string
  718. ErrorMessage string
  719. ValidateApplyV2 bool
  720. }
  721. // StackLaunchFailureTrack returns a track for when a user fails creating a stack
  722. func StackLaunchFailureTrack(opts *StackLaunchFailureOpts) 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["error_message"] = opts.ErrorMessage
  729. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  730. return getSegmentProjectTrack(
  731. opts.ProjectScopedTrackOpts,
  732. getDefaultSegmentTrack(additionalProps, StackLaunchFailure),
  733. )
  734. }
  735. // StackDeletionOpts are the options for creating a track when a user deletes a stack
  736. type StackDeletionOpts struct {
  737. *ProjectScopedTrackOpts
  738. StackName string
  739. Email string
  740. FirstName string
  741. LastName string
  742. CompanyName string
  743. DeleteWorkflowFile bool
  744. ValidateApplyV2 bool
  745. }
  746. // StackDeletionTrack returns a track for when a user deletes a stack
  747. func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
  748. additionalProps := make(map[string]interface{})
  749. additionalProps["stack_name"] = opts.StackName
  750. additionalProps["email"] = opts.Email
  751. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  752. additionalProps["company"] = opts.CompanyName
  753. additionalProps["delete_workflow_file"] = opts.DeleteWorkflowFile
  754. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  755. return getSegmentProjectTrack(
  756. opts.ProjectScopedTrackOpts,
  757. getDefaultSegmentTrack(additionalProps, StackDeletion),
  758. )
  759. }
  760. // StackBuildOpts are the options for creating a track when a stack builds
  761. type StackBuildOpts struct {
  762. *ProjectScopedTrackOpts
  763. StackName string
  764. ErrorMessage string
  765. B64BuildLogs string
  766. Email string
  767. FirstName string
  768. LastName string
  769. CompanyName string
  770. ValidateApplyV2 bool
  771. }
  772. // StackBuildFailureTrack returns a track for when a stack fails to build
  773. func StackBuildFailureTrack(opts *StackBuildOpts) segmentTrack {
  774. additionalProps := make(map[string]interface{})
  775. additionalProps["stack_name"] = opts.StackName
  776. additionalProps["error_message"] = opts.ErrorMessage
  777. additionalProps["email"] = opts.Email
  778. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  779. additionalProps["company"] = opts.CompanyName
  780. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  781. additionalProps["b64_build_logs"] = opts.B64BuildLogs
  782. return getSegmentProjectTrack(
  783. opts.ProjectScopedTrackOpts,
  784. getDefaultSegmentTrack(additionalProps, StackBuildFailure),
  785. )
  786. }
  787. // StackBuildSuccessTrack returns a track for when a stack succeeds to build
  788. func StackBuildSuccessTrack(opts *StackBuildOpts) segmentTrack {
  789. additionalProps := make(map[string]interface{})
  790. additionalProps["stack_name"] = opts.StackName
  791. additionalProps["email"] = opts.Email
  792. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  793. additionalProps["company"] = opts.CompanyName
  794. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  795. return getSegmentProjectTrack(
  796. opts.ProjectScopedTrackOpts,
  797. getDefaultSegmentTrack(additionalProps, StackBuildSuccess),
  798. )
  799. }
  800. // StackBuildProgressingTrack returns a track for when a stack starts to build
  801. func StackBuildProgressingTrack(opts *StackBuildOpts) segmentTrack {
  802. additionalProps := make(map[string]interface{})
  803. additionalProps["stack_name"] = opts.StackName
  804. additionalProps["email"] = opts.Email
  805. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  806. additionalProps["company"] = opts.CompanyName
  807. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  808. return getSegmentProjectTrack(
  809. opts.ProjectScopedTrackOpts,
  810. getDefaultSegmentTrack(additionalProps, StackBuildProgressing),
  811. )
  812. }
  813. // PorterAppUpdateOpts are the options for creating a track when a user updates a porter app
  814. type PorterAppUpdateOpts struct {
  815. *ProjectScopedTrackOpts
  816. StackName string
  817. Email string
  818. FirstName string
  819. LastName string
  820. CompanyName string
  821. ErrorMessage string
  822. ErrorStackTrace string
  823. ValidateApplyV2 bool
  824. }
  825. // PorterAppUpdateFailureTrack returns a track for when a user attempts to update an app and receives an error
  826. func PorterAppUpdateFailureTrack(opts *PorterAppUpdateOpts) segmentTrack {
  827. additionalProps := make(map[string]interface{})
  828. additionalProps["stack_name"] = opts.StackName
  829. additionalProps["email"] = opts.Email
  830. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  831. additionalProps["company"] = opts.CompanyName
  832. additionalProps["error_message"] = opts.ErrorMessage
  833. additionalProps["error_stack_trace"] = opts.ErrorStackTrace
  834. additionalProps["validate_apply_v2"] = opts.ValidateApplyV2
  835. return getSegmentProjectTrack(
  836. opts.ProjectScopedTrackOpts,
  837. getDefaultSegmentTrack(additionalProps, PorterAppUpdateFailure),
  838. )
  839. }