Skip to content

Latest commit

 

History

History
116 lines (80 loc) · 2.84 KB

File metadata and controls

116 lines (80 loc) · 2.84 KB

Medusa v2 Example: Segment Integration

This directory holds the code for the Segment Integration Tutorial.

You can either:

Prerequisites

Installation

  1. Clone the repository and change to the segment-integration directory:
git clone https://github.com/medusajs/examples.git
cd examples/segment-integration

2. Rename the .env.template file to .env.

3. If necessary, change the PostgreSQL username, password, and host in the DATABASE_URL environment variable.

4. Set the Segment environment variable:

SEGMENT_WRITE_KEY=

Where its value is the Write API key of the Node.js source in segment.

Learn more about retrieving these variables in the tutorial

5. Install dependencies:

yarn # or npm install

6. Setup and seed the database:

npx medusa db:setup
yarn seed # or npm run seed

7. Start the Medusa application:

yarn dev # or npm run dev

You can test the integration out by placing an order.

Copy into Existing Medusa Application

If you have an existing Medusa application, copy the following directories and files into your project:

  • src/modules/segment
  • src/subscribers
  • src/workflows

Then, add the Segment Module Provider to medusa-config.ts:

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/analytics",
      options: {
        providers: [
          {
            resolve: "./src/modules/segment",
            id: "segment",
            options: {
              writeKey: process.env.SEGMENT_WRITE_KEY || "",
            },
          },
        ],
      },
    },
  ]
})

Next, add the following environment variable:

SEGMENT_WRITE_KEY=

Where its value is the Write API key of the Node.js source in segment.

Learn more about retrieving these variables in the tutorial

After that, install the @segment/analytics-node package:

yarn add @segment/analytics-node # or npm install @segment/analytics-node

This guide was implemented with @segment/analytics-node@^2.2.1.

You can test the integration out by placing an order.

More Resources