tracks.go 26 KB

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