{"id":30312723,"url":"https://github.com/mparticle/mparticle-go-sdk","last_synced_at":"2026-01-20T18:09:03.944Z","repository":{"id":38095457,"uuid":"219804299","full_name":"mParticle/mparticle-go-sdk","owner":"mParticle","description":"Go SDK for the mParticle Events API","archived":false,"fork":false,"pushed_at":"2022-11-01T10:47:49.000Z","size":46,"stargazers_count":0,"open_issues_count":2,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-21T18:59:06.348Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mParticle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-05T17:31:53.000Z","updated_at":"2022-02-02T14:37:01.000Z","dependencies_parsed_at":"2023-01-21T00:48:09.857Z","dependency_job_id":null,"html_url":"https://github.com/mParticle/mparticle-go-sdk","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/mParticle/mparticle-go-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mParticle%2Fmparticle-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mParticle%2Fmparticle-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mParticle%2Fmparticle-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mParticle%2Fmparticle-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mParticle","download_url":"https://codeload.github.com/mParticle/mparticle-go-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mParticle%2Fmparticle-go-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270877422,"owners_count":24661139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-17T17:14:23.151Z","updated_at":"2026-01-20T18:09:03.915Z","avatar_url":"https://github.com/mParticle.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://static.mparticle.com/sdk/mp_logo_black.svg\" width=\"280\"\u003e\n\n## Go Events SDK\n\nThis is the mParticle Go SDK for the server-based Events API - use it to send your data to the [mParticle platform](https://www.mparticle.com/) and off to 250+ integrations!\n\n## Getting Started \n\n### Get the Dependency\n\n```sh\ngo get github.com/mParticle/mparticle-go-sdk/events\n```\n\n### Import the `events` Package\n\n```go\nimport \"github.com/mParticle/mparticle-go-sdk/events\"\n```\n\n## Create a `Batch`\n\nAll data that passes through mParticle does so in the form of a \"batch.\" A batch describes identities, attributes, events, and other information related to a *single user*. This SDK lets you upload either single batches or multiple batches at a time.\n\nThe full schema of a batch is documented in the [mParticle Events API overview](https://docs.mparticle.com/developers/server/http/). The models in this SDK directly match the JSON referenced in the overview.\n\n```go\nbatch := events.Batch{Environment: events.DevelopmentEnvironment} //or \"ProductionEnvironment\"\n\n//set user identities\nbatch.UserIdentities = \u0026events.UserIdentities{\n    CustomerID: \"go1234\",\n    Email:      \"go-example@foo.com\",\n}\n\n//set device identities\nbatch.DeviceInfo = \u0026events.DeviceInformation{\n    IOSAdvertisingID: \"607258d9-c28b-43ad-95ed-e9593025d5a1\",\n}\n\n//set user attributes\nbatch.UserAttributes = make(map[string]interface{})\nbatch.UserAttributes[\"foo\"] = \"bar\"\nbatch.UserAttributes[\"foo-array\"] = []string{\"bar1\", \"bar2\"}\n```\n\n\u003e It's critical to include either user or device identities with your server-side data\n\n## Create Events\n\nAll mParticle events have a similar structure:\n\n- `event_type`: this is the type of event, such as `custom_event` and `commerce_event`\n- `data`: this contains common properties of all events, as well as properties specific to each `event_type`\n\nThe following are common properties that all events share, as represented by the `CommonEventData` struct:\n\n```javascript\n{\n    \"event_id\" : 6004677780660780000,\n    \"source_message_id\" : \"e8335d31-2031-4bff-afec-17ffc1784697\",\n    \"session_id\" : 4957918240501247982,\n    \"session_uuid\" : \"91b86d0c-86cb-4124-a8b2-edee107de454\",\n    \"timestamp_unixtime_ms\" : 1402521613976,\n    \"location\" : {},\n    \"device_current_state\" : {},\n    \"custom_attributes\": {},\n    \"custom_flags\": {}\n}\n```\n\nThe Go Events SDK represents this structure via an event and an event-data struct for each unique event type. For convenience, every event struct provides a constructor to autopopulate the correct event type and data object, for example `NewCustomEvent()`, `NewScreenViewEvent()`, and `NewCommerceEvent()`:\n\n### Custom Events\n\n```go\ncustomEvent := events.NewCustomEvent()\ncustomEvent.Data.EventName = \"My Custom Event Name\"\ncustomEvent.Data.CustomEventType = events.OtherCustomEventType\ncustomEvent.Data.CustomAttributes = make(map[string]string)\ncustomEvent.Data.CustomAttributes[\"foo\"] = \"bar\"\n```\n\n### Screen Events\n\n```go\nscreenEvent := events.NewScreenViewEvent()\nscreenEvent.Data.ScreenName = \"My Screen Name\"\n```\n\n### Commerce Events\n\n```go\ntotalProductAmount := 123.12\nproduct := events.Product{\n    TotalProductAmount: \u0026totalProductAmount,\n    ID:                 \"product-id\",\n    Name:               \"product-name\",\n}\n\t\ncommerceEvent := events.NewCommerceEvent()\ntotalPurchaseAmount := 123.12\ncommerceEvent.Data.ProductAction = \u0026events.ProductAction{\n    Action:        events.PurchaseAction,\n    TotalAmount:   \u0026totalProductAmount,\n    TransactionID: \"foo-transaction-id\",\n    Products:      []events.Product{product},\n}\n```\n\n## Full Upload Example\n\nThe SDK supports both multi-batch (\"bulk\") or single-batch uploads:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/mParticle/mparticle-go-sdk/events\"\n)\n\nfunc main() {\n\tclient := events.NewAPIClient(events.NewConfiguration())\n\n\tctx := context.WithValue(\n\t\tcontext.Background(),\n\t\tevents.ContextBasicAuth,\n\t\tevents.BasicAuth{\n\t\t\tAPIKey:    \"REPLACE WITH API KEY\",\n\t\t\tAPISecret: \"REPLACE WITH API SECRET\",\n\t\t},\n\t)\n\tbatch := events.Batch{Environment: events.DevelopmentEnvironment} //or \"ProductionEnvironment\"\n\n\t//set user identities\n\tbatch.UserIdentities = \u0026events.UserIdentities{\n\t\tCustomerID: \"go1234\",\n\t\tEmail:      \"go-example@foo.com\",\n\t}\n\n\t//set context\n\tbatch.BatchContext = \u0026events.BatchContext{\n\t\t//configure data plan\n\t\tDataPlan: \u0026events.DataPlanContext{\n\t\t\tPlanID:      \"freddy_s_plan\",\n\t\t\tPlanVersion: 1,\n\t\t},\n\t}\n\n\t//set device identities\n\tbatch.DeviceInfo = \u0026events.DeviceInformation{\n\t\tIOSAdvertisingID: \"607258d9-c28b-43ad-95ed-e9593025d5a1\",\n\t}\n\n\t//set user attributes\n\tbatch.UserAttributes = make(map[string]interface{})\n\tbatch.UserAttributes[\"foo\"] = \"bar\"\n\tbatch.UserAttributes[\"foo-array\"] = []string{\"bar1\", \"bar2\"}\n\n\tcustomEvent := events.NewCustomEvent()\n\tcustomEvent.Data.EventName = \"My Custom Event Name\"\n\tcustomEvent.Data.CustomEventType = events.OtherCustomEventType\n\tcustomEvent.Data.CustomAttributes = make(map[string]string)\n\tcustomEvent.Data.CustomAttributes[\"foo\"] = \"bar\"\n\n\tscreenEvent := events.NewScreenViewEvent()\n\tscreenEvent.Data.ScreenName = \"My Screen Name\"\n\n\ttotalProductAmount := 123.12\n\tproduct := events.Product{\n\t\tTotalProductAmount: \u0026totalProductAmount,\n\t\tID:                 \"product-id\",\n\t\tName:               \"product-name\",\n\t}\n\n\tcommerceEvent := events.NewCommerceEvent()\n\ttotalPurchaseAmount := 123.12\n\tcommerceEvent.Data.ProductAction = \u0026events.ProductAction{\n\t\tAction:        events.PurchaseAction,\n\t\tTotalAmount:   \u0026totalPurchaseAmount,\n\t\tTransactionID: \"foo-transaction-id\",\n\t\tProducts:      []events.Product{product},\n\t}\n\n\tbatch.Events = []events.Event{customEvent, screenEvent, commerceEvent}\n\n\tresult, err := client.EventsAPI.UploadEvents(ctx, batch)\n\tif result != nil \u0026\u0026 result.StatusCode == 202 {\n\t\tfmt.Println(\"Upload successful\")\n\t} else {\n\t\tfmt.Errorf(\n\t\t\t\"Error while uploading!\\nstatus: %v\\nresponse body: %#v\",\n\t\t\terr.(events.GenericError).Error(),\n\t\t\terr.(events.GenericError).Model())\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmparticle%2Fmparticle-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmparticle%2Fmparticle-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmparticle%2Fmparticle-go-sdk/lists"}