tracks.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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. }
  322. // ProvisioningAttemptTrack returns a track for when a user attempts provisioning
  323. func ProvisioningAttemptTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  324. additionalProps := make(map[string]interface{})
  325. additionalProps["email"] = opts.Email
  326. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  327. additionalProps["company"] = opts.CompanyName
  328. additionalProps["region"] = opts.Region
  329. return getSegmentProjectTrack(
  330. opts.ProjectScopedTrackOpts,
  331. getDefaultSegmentTrack(additionalProps, ProvisioningAttempted),
  332. )
  333. }
  334. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  335. func ProvisionFailureTrack(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["error_message"] = opts.ErrorMessage
  341. additionalProps["region"] = opts.Region
  342. return getSegmentProjectTrack(
  343. opts.ProjectScopedTrackOpts,
  344. getDefaultSegmentTrack(additionalProps, ProvisioningFailure),
  345. )
  346. }
  347. // ClusterProvisioningStartTrackOpts are the options for creating a track when a cluster
  348. // has started provisioning
  349. type ClusterProvisioningStartTrackOpts struct {
  350. // note that this is a project-scoped track, since the cluster has not been created yet
  351. *ProjectScopedTrackOpts
  352. ClusterType types.InfraKind
  353. InfraID uint
  354. }
  355. // ClusterProvisioningStartTrack returns a track for when a cluster
  356. // has started provisioning
  357. func ClusterProvisioningStartTrack(opts *ClusterProvisioningStartTrackOpts) segmentTrack {
  358. additionalProps := make(map[string]interface{})
  359. additionalProps["cluster_type"] = opts.ClusterType
  360. additionalProps["infra_id"] = opts.InfraID
  361. return getSegmentProjectTrack(
  362. opts.ProjectScopedTrackOpts,
  363. getDefaultSegmentTrack(additionalProps, ClusterProvisioningStart),
  364. )
  365. }
  366. // ClusterProvisioningErrorTrackOpts are the options for creating a track when a cluster
  367. // has experienced a provisioning error
  368. type ClusterProvisioningErrorTrackOpts struct {
  369. // note that this is a project-scoped track, since the cluster has not been created yet
  370. *ProjectScopedTrackOpts
  371. ClusterType types.InfraKind
  372. InfraID uint
  373. }
  374. // ClusterProvisioningErrorTrack returns a track for when a cluster
  375. // has experienced a provisioning error
  376. func ClusterProvisioningErrorTrack(opts *ClusterProvisioningErrorTrackOpts) segmentTrack {
  377. additionalProps := make(map[string]interface{})
  378. additionalProps["cluster_type"] = opts.ClusterType
  379. additionalProps["infra_id"] = opts.InfraID
  380. return getSegmentProjectTrack(
  381. opts.ProjectScopedTrackOpts,
  382. getDefaultSegmentTrack(additionalProps, ClusterProvisioningError),
  383. )
  384. }
  385. // ClusterProvisioningSuccessTrackOpts are the options for creating a track when a cluster
  386. // has successfully provisioned
  387. type ClusterProvisioningSuccessTrackOpts struct {
  388. *ClusterScopedTrackOpts
  389. ClusterType types.InfraKind
  390. InfraID uint
  391. }
  392. // ClusterProvisioningSuccessTrack returns a new track for when a cluster
  393. // has successfully provisioned
  394. func ClusterProvisioningSuccessTrack(opts *ClusterProvisioningSuccessTrackOpts) segmentTrack {
  395. additionalProps := make(map[string]interface{})
  396. additionalProps["cluster_type"] = opts.ClusterType
  397. additionalProps["infra_id"] = opts.InfraID
  398. return getSegmentClusterTrack(
  399. opts.ClusterScopedTrackOpts,
  400. getDefaultSegmentTrack(additionalProps, ClusterProvisioningSuccess),
  401. )
  402. }
  403. // ClusterConnectionStartTrackOpts are the options for creating a track when a cluster
  404. // connection has started
  405. type ClusterConnectionStartTrackOpts struct {
  406. // note that this is a project-scoped track, since the cluster has not been created yet
  407. *ProjectScopedTrackOpts
  408. ClusterCandidateID uint
  409. }
  410. // ClusterConnectionStartTrack returns a new track for when a cluster
  411. // connection has started
  412. func ClusterConnectionStartTrack(opts *ClusterConnectionStartTrackOpts) segmentTrack {
  413. additionalProps := make(map[string]interface{})
  414. additionalProps["cc_id"] = opts.ClusterCandidateID
  415. return getSegmentProjectTrack(
  416. opts.ProjectScopedTrackOpts,
  417. getDefaultSegmentTrack(additionalProps, ClusterConnectionStart),
  418. )
  419. }
  420. // ClusterConnectionSuccessTrackOpts are the options for creating a track when a cluster
  421. // connection has finished
  422. type ClusterConnectionSuccessTrackOpts struct {
  423. *ClusterScopedTrackOpts
  424. ClusterCandidateID uint
  425. }
  426. // ClusterConnectionSuccessTrack returns a new track for when a cluster
  427. // connection has finished
  428. func ClusterConnectionSuccessTrack(opts *ClusterConnectionSuccessTrackOpts) segmentTrack {
  429. additionalProps := make(map[string]interface{})
  430. additionalProps["cc_id"] = opts.ClusterCandidateID
  431. return getSegmentClusterTrack(
  432. opts.ClusterScopedTrackOpts,
  433. getDefaultSegmentTrack(additionalProps, ClusterConnectionSuccess),
  434. )
  435. }
  436. // RegistryConnectionStartTrackOpts are the options for creating a track when a registry
  437. // connection has started
  438. type RegistryConnectionStartTrackOpts struct {
  439. // note that this is a project-scoped track, since the cluster has not been created yet
  440. *ProjectScopedTrackOpts
  441. // a random id assigned to this connection request
  442. FlowID string
  443. }
  444. // RegistryConnectionStartTrack returns a new track for when a registry
  445. // connection has started
  446. func RegistryConnectionStartTrack(opts *RegistryConnectionStartTrackOpts) segmentTrack {
  447. additionalProps := make(map[string]interface{})
  448. additionalProps["flow_id"] = opts.FlowID
  449. return getSegmentProjectTrack(
  450. opts.ProjectScopedTrackOpts,
  451. getDefaultSegmentTrack(additionalProps, RegistryConnectionStart),
  452. )
  453. }
  454. // RegistryConnectionSuccessTrackOpts are the options for creating a track when a registry
  455. // connection has completed
  456. type RegistryConnectionSuccessTrackOpts struct {
  457. *RegistryScopedTrackOpts
  458. // a random id assigned to this connection request
  459. FlowID string
  460. }
  461. // RegistryConnectionSuccessTrack returns a new track for when a registry
  462. // connection has completed
  463. func RegistryConnectionSuccessTrack(opts *RegistryConnectionSuccessTrackOpts) segmentTrack {
  464. additionalProps := make(map[string]interface{})
  465. additionalProps["flow_id"] = opts.FlowID
  466. return getSegmentRegistryTrack(
  467. opts.RegistryScopedTrackOpts,
  468. getDefaultSegmentTrack(additionalProps, RegistryConnectionSuccess),
  469. )
  470. }
  471. // GithubConnectionStartTrackOpts are the options for creating a track when a github account
  472. // connection has started
  473. type GithubConnectionStartTrackOpts struct {
  474. // note that this is a user-scoped track, since github repos are tied to the user
  475. *UserScopedTrackOpts
  476. }
  477. // GithubConnectionStartTrack returns a new track for when a github account
  478. // connection has started
  479. func GithubConnectionStartTrack(opts *GithubConnectionStartTrackOpts) segmentTrack {
  480. additionalProps := make(map[string]interface{})
  481. return getSegmentUserTrack(
  482. opts.UserScopedTrackOpts,
  483. getDefaultSegmentTrack(additionalProps, GithubConnectionStart),
  484. )
  485. }
  486. // GithubConnectionSuccessTrackOpts are the options for creating a track when a github account
  487. // connection has completed
  488. type GithubConnectionSuccessTrackOpts struct {
  489. // note that this is a user-scoped track, since github repos are tied to the user
  490. *UserScopedTrackOpts
  491. }
  492. // GithubConnectionSuccessTrack returns a new track when a github account
  493. // connection has completed
  494. func GithubConnectionSuccessTrack(opts *GithubConnectionSuccessTrackOpts) segmentTrack {
  495. additionalProps := make(map[string]interface{})
  496. return getSegmentUserTrack(
  497. opts.UserScopedTrackOpts,
  498. getDefaultSegmentTrack(additionalProps, GithubConnectionSuccess),
  499. )
  500. }
  501. // ApplicationLaunchStartTrackOpts are the options for creating a track when an application
  502. // launch has started
  503. type ApplicationLaunchStartTrackOpts struct {
  504. *ClusterScopedTrackOpts
  505. FlowID string
  506. }
  507. // ApplicationLaunchStartTrack returns a new track for when an application
  508. // launch has started
  509. func ApplicationLaunchStartTrack(opts *ApplicationLaunchStartTrackOpts) segmentTrack {
  510. additionalProps := make(map[string]interface{})
  511. additionalProps["flow_id"] = opts.FlowID
  512. return getSegmentClusterTrack(
  513. opts.ClusterScopedTrackOpts,
  514. getDefaultSegmentTrack(additionalProps, ApplicationLaunchStart),
  515. )
  516. }
  517. // ApplicationLaunchSuccessTrackOpts are the options for creating a track when an application
  518. // launch has completed
  519. type ApplicationLaunchSuccessTrackOpts struct {
  520. *ApplicationScopedTrackOpts
  521. FlowID string
  522. }
  523. // ApplicationLaunchSuccessTrack returns a new track for when an application
  524. // launch has completed
  525. func ApplicationLaunchSuccessTrack(opts *ApplicationLaunchSuccessTrackOpts) segmentTrack {
  526. additionalProps := make(map[string]interface{})
  527. additionalProps["flow_id"] = opts.FlowID
  528. return getSegmentApplicationTrack(
  529. opts.ApplicationScopedTrackOpts,
  530. getDefaultSegmentTrack(additionalProps, ApplicationLaunchSuccess),
  531. )
  532. }
  533. // ApplicationDeploymentWebhookTrackOpts are the options for creating a track when an application
  534. // launch has completed from a webhook
  535. type ApplicationDeploymentWebhookTrackOpts struct {
  536. *ApplicationScopedTrackOpts
  537. ImageURI string
  538. }
  539. // ApplicationDeploymentWebhookTrack returns a new track for when an application
  540. // launch has completed from a webhook
  541. func ApplicationDeploymentWebhookTrack(opts *ApplicationDeploymentWebhookTrackOpts) segmentTrack {
  542. additionalProps := make(map[string]interface{})
  543. additionalProps["image_uri"] = opts.ImageURI
  544. return getSegmentApplicationTrack(
  545. opts.ApplicationScopedTrackOpts,
  546. getDefaultSegmentTrack(additionalProps, ApplicationDeploymentWebhook),
  547. )
  548. }
  549. // RegistryProvisioningStartTrackOpts are the options for creating a track when a registry
  550. // provisioning has started
  551. type RegistryProvisioningStartTrackOpts struct {
  552. // note that this is a project-scoped track, since the registry has not been created yet
  553. *ProjectScopedTrackOpts
  554. RegistryType types.InfraKind
  555. InfraID uint
  556. }
  557. // RegistryProvisioningStartTrack returns a new track for when a registry
  558. // provisioning has started
  559. func RegistryProvisioningStartTrack(opts *RegistryProvisioningStartTrackOpts) segmentTrack {
  560. additionalProps := make(map[string]interface{})
  561. additionalProps["registry_type"] = opts.RegistryType
  562. additionalProps["infra_id"] = opts.InfraID
  563. return getSegmentProjectTrack(
  564. opts.ProjectScopedTrackOpts,
  565. getDefaultSegmentTrack(additionalProps, RegistryProvisioningStart),
  566. )
  567. }
  568. // RegistryProvisioningErrorTrackOpts are the options for creating a track when a registry
  569. // provisioning has failed
  570. type RegistryProvisioningErrorTrackOpts struct {
  571. // note that this is a project-scoped track, since the registry has not been created yet
  572. *ProjectScopedTrackOpts
  573. RegistryType types.InfraKind
  574. InfraID uint
  575. }
  576. // RegistryProvisioningErrorTrack returns a new track for when a registry
  577. // provisioning has failed
  578. func RegistryProvisioningErrorTrack(opts *RegistryProvisioningErrorTrackOpts) segmentTrack {
  579. additionalProps := make(map[string]interface{})
  580. additionalProps["registry_type"] = opts.RegistryType
  581. additionalProps["infra_id"] = opts.InfraID
  582. return getSegmentProjectTrack(
  583. opts.ProjectScopedTrackOpts,
  584. getDefaultSegmentTrack(additionalProps, RegistryProvisioningError),
  585. )
  586. }
  587. // RegistryProvisioningSuccessTrackOpts are the options for creating a track when a registry
  588. // provisioning has completed
  589. type RegistryProvisioningSuccessTrackOpts struct {
  590. *RegistryScopedTrackOpts
  591. RegistryType types.InfraKind
  592. InfraID uint
  593. }
  594. // RegistryProvisioningSuccessTrack returns a new track for when a registry
  595. // provisioning has completed
  596. func RegistryProvisioningSuccessTrack(opts *RegistryProvisioningSuccessTrackOpts) segmentTrack {
  597. additionalProps := make(map[string]interface{})
  598. additionalProps["registry_type"] = opts.RegistryType
  599. additionalProps["infra_id"] = opts.InfraID
  600. return getSegmentRegistryTrack(
  601. opts.RegistryScopedTrackOpts,
  602. getDefaultSegmentTrack(additionalProps, RegistryProvisioningSuccess),
  603. )
  604. }
  605. // ClusterDestroyingStartTrackOpts are the options for creating a track when a cluster
  606. // has started destroying
  607. type ClusterDestroyingStartTrackOpts struct {
  608. *ClusterScopedTrackOpts
  609. ClusterType types.InfraKind
  610. InfraID uint
  611. }
  612. // ClusterDestroyingStartTrack returns a track for when a cluster
  613. // has started destroying
  614. func ClusterDestroyingStartTrack(opts *ClusterDestroyingStartTrackOpts) segmentTrack {
  615. additionalProps := make(map[string]interface{})
  616. additionalProps["cluster_type"] = opts.ClusterType
  617. additionalProps["infra_id"] = opts.InfraID
  618. return getSegmentClusterTrack(
  619. opts.ClusterScopedTrackOpts,
  620. getDefaultSegmentTrack(additionalProps, ClusterDestroyingStart),
  621. )
  622. }
  623. // ClusterDestroyingSuccessTrackOpts are the options for creating a track when a cluster
  624. // has successfully provisioned
  625. type ClusterDestroyingSuccessTrackOpts struct {
  626. *ClusterScopedTrackOpts
  627. ClusterType types.InfraKind
  628. InfraID uint
  629. }
  630. // ClusterDestroyingSuccessTrack returns a new track for when a cluster
  631. // has successfully provisioned
  632. func ClusterDestroyingSuccessTrack(opts *ClusterDestroyingSuccessTrackOpts) segmentTrack {
  633. additionalProps := make(map[string]interface{})
  634. additionalProps["cluster_type"] = opts.ClusterType
  635. additionalProps["infra_id"] = opts.InfraID
  636. return getSegmentClusterTrack(
  637. opts.ClusterScopedTrackOpts,
  638. getDefaultSegmentTrack(additionalProps, ClusterDestroyingSuccess),
  639. )
  640. }
  641. // StackLaunchStartOpts are the options for creating a track when a user starts creating a stack
  642. type StackLaunchStartOpts struct {
  643. *ProjectScopedTrackOpts
  644. Email string
  645. FirstName string
  646. LastName string
  647. CompanyName string
  648. }
  649. // StackLaunchStartTrack returns a track for when a user starts creating a stack
  650. func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
  651. additionalProps := make(map[string]interface{})
  652. additionalProps["email"] = opts.Email
  653. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  654. additionalProps["company"] = opts.CompanyName
  655. return getSegmentProjectTrack(
  656. opts.ProjectScopedTrackOpts,
  657. getDefaultSegmentTrack(additionalProps, StackLaunchStart),
  658. )
  659. }
  660. // StackLaunchCompleteOpts are the options for creating a track when a user completes creating a stack
  661. type StackLaunchCompleteOpts struct {
  662. *ProjectScopedTrackOpts
  663. StackName string
  664. Email string
  665. FirstName string
  666. LastName string
  667. CompanyName string
  668. }
  669. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  670. func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
  671. additionalProps := make(map[string]interface{})
  672. additionalProps["stack_name"] = opts.StackName
  673. additionalProps["email"] = opts.Email
  674. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  675. additionalProps["company"] = opts.CompanyName
  676. return getSegmentProjectTrack(
  677. opts.ProjectScopedTrackOpts,
  678. getDefaultSegmentTrack(additionalProps, StackLaunchComplete),
  679. )
  680. }
  681. // StackLaunchSuccessOpts are the options for creating a track when a user succeeds in creating a stack
  682. type StackLaunchSuccessOpts struct {
  683. *ProjectScopedTrackOpts
  684. StackName string
  685. Email string
  686. FirstName string
  687. LastName string
  688. CompanyName string
  689. }
  690. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  691. func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
  692. additionalProps := make(map[string]interface{})
  693. additionalProps["stack_name"] = opts.StackName
  694. additionalProps["email"] = opts.Email
  695. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  696. additionalProps["company"] = opts.CompanyName
  697. return getSegmentProjectTrack(
  698. opts.ProjectScopedTrackOpts,
  699. getDefaultSegmentTrack(additionalProps, StackLaunchSuccess),
  700. )
  701. }
  702. // StackLaunchFailureOpts are the options for creating a track when a user fails in creating a stack
  703. type StackLaunchFailureOpts struct {
  704. *ProjectScopedTrackOpts
  705. StackName string
  706. Email string
  707. FirstName string
  708. LastName string
  709. CompanyName string
  710. ErrorMessage string
  711. }
  712. // StackLaunchFailureTrack returns a track for when a user fails creating a stack
  713. func StackLaunchFailureTrack(opts *StackLaunchFailureOpts) segmentTrack {
  714. additionalProps := make(map[string]interface{})
  715. additionalProps["stack_name"] = opts.StackName
  716. additionalProps["email"] = opts.Email
  717. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  718. additionalProps["company"] = opts.CompanyName
  719. additionalProps["error_message"] = opts.ErrorMessage
  720. return getSegmentProjectTrack(
  721. opts.ProjectScopedTrackOpts,
  722. getDefaultSegmentTrack(additionalProps, StackLaunchFailure),
  723. )
  724. }
  725. // StackDeletionOpts are the options for creating a track when a user deletes a stack
  726. type StackDeletionOpts struct {
  727. *ProjectScopedTrackOpts
  728. StackName string
  729. Email string
  730. FirstName string
  731. LastName string
  732. CompanyName string
  733. DeleteWorkflowFile bool
  734. }
  735. // StackDeletionTrack returns a track for when a user deletes a stack
  736. func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
  737. additionalProps := make(map[string]interface{})
  738. additionalProps["stack_name"] = opts.StackName
  739. additionalProps["email"] = opts.Email
  740. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  741. additionalProps["company"] = opts.CompanyName
  742. additionalProps["delete_workflow_file"] = opts.DeleteWorkflowFile
  743. return getSegmentProjectTrack(
  744. opts.ProjectScopedTrackOpts,
  745. getDefaultSegmentTrack(additionalProps, StackDeletion),
  746. )
  747. }
  748. // StackBuildOpts are the options for creating a track when a stack builds
  749. type StackBuildOpts struct {
  750. *ProjectScopedTrackOpts
  751. StackName string
  752. ErrorMessage string
  753. Email string
  754. FirstName string
  755. LastName string
  756. CompanyName string
  757. }
  758. // StackBuildFailureTrack returns a track for when a stack fails to build
  759. func StackBuildFailureTrack(opts *StackBuildOpts) segmentTrack {
  760. additionalProps := make(map[string]interface{})
  761. additionalProps["stack_name"] = opts.StackName
  762. additionalProps["error_message"] = opts.ErrorMessage
  763. additionalProps["email"] = opts.Email
  764. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  765. additionalProps["company"] = opts.CompanyName
  766. return getSegmentProjectTrack(
  767. opts.ProjectScopedTrackOpts,
  768. getDefaultSegmentTrack(additionalProps, StackBuildFailure),
  769. )
  770. }
  771. // StackBuildSuccessTrack returns a track for when a stack succeeds to build
  772. func StackBuildSuccessTrack(opts *StackBuildOpts) segmentTrack {
  773. additionalProps := make(map[string]interface{})
  774. additionalProps["stack_name"] = opts.StackName
  775. additionalProps["email"] = opts.Email
  776. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  777. additionalProps["company"] = opts.CompanyName
  778. return getSegmentProjectTrack(
  779. opts.ProjectScopedTrackOpts,
  780. getDefaultSegmentTrack(additionalProps, StackBuildSuccess),
  781. )
  782. }
  783. // StackBuildProgressingTrack returns a track for when a stack starts to build
  784. func StackBuildProgressingTrack(opts *StackBuildOpts) segmentTrack {
  785. additionalProps := make(map[string]interface{})
  786. additionalProps["stack_name"] = opts.StackName
  787. additionalProps["email"] = opts.Email
  788. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  789. additionalProps["company"] = opts.CompanyName
  790. return getSegmentProjectTrack(
  791. opts.ProjectScopedTrackOpts,
  792. getDefaultSegmentTrack(additionalProps, StackBuildProgressing),
  793. )
  794. }