tracks.go 29 KB

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