tracks.go 30 KB

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