diff --git a/packages/browser-destinations/destinations/moengage-web/README.md b/packages/browser-destinations/destinations/moengage-web/README.md new file mode 100644 index 00000000000..65d5d0a3e3e --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/README.md @@ -0,0 +1,31 @@ +# @segment/analytics-browser-actions-moengage-web + +The Moengage Web browser action destination for use with @segment/analytics-next. + +## License + +MIT License + +Copyright (c) 2025 Segment + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +## Contributing + +All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under. diff --git a/packages/browser-destinations/destinations/moengage-web/package.json b/packages/browser-destinations/destinations/moengage-web/package.json new file mode 100644 index 00000000000..9a7e7253d1e --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/package.json @@ -0,0 +1,24 @@ +{ + "name": "@segment/analytics-browser-actions-moengage-web", + "version": "1.0.0", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/segmentio/action-destinations", + "directory": "packages/browser-destinations/destinations/moengage-web" + }, + "main": "./dist/cjs", + "module": "./dist/esm", + "scripts": { + "build": "yarn build:esm && yarn build:cjs", + "build:cjs": "tsc --module commonjs --outDir ./dist/cjs", + "build:esm": "tsc --outDir ./dist/esm" + }, + "typings": "./dist/esm", + "dependencies": { + "@segment/browser-destination-runtime": "^1.4.0" + }, + "peerDependencies": { + "@segment/analytics-next": ">=1.55.0" + } +} diff --git a/packages/browser-destinations/destinations/moengage-web/src/__tests__/index.test.ts b/packages/browser-destinations/destinations/moengage-web/src/__tests__/index.test.ts new file mode 100644 index 00000000000..72fed71b8e8 --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/__tests__/index.test.ts @@ -0,0 +1,4 @@ +import { Analytics, Context } from '@segment/analytics-next' +import plugins, { destination } from '../index' + +describe('Moengage Web', () => {}) diff --git a/packages/browser-destinations/destinations/moengage-web/src/generated-types.ts b/packages/browser-destinations/destinations/moengage-web/src/generated-types.ts new file mode 100644 index 00000000000..4ab2786ec60 --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/generated-types.ts @@ -0,0 +1,3 @@ +// Generated file. DO NOT MODIFY IT BY HAND. + +export interface Settings {} diff --git a/packages/browser-destinations/destinations/moengage-web/src/index.ts b/packages/browser-destinations/destinations/moengage-web/src/index.ts new file mode 100644 index 00000000000..1ea7e70cacd --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/index.ts @@ -0,0 +1,30 @@ +import type { Settings } from './generated-types' +import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types' +import { browserDestination } from '@segment/browser-destination-runtime/shim' + +import trackEvent from './trackEvent' + +// Switch from unknown to the partner SDK client types +export const destination: BrowserDestinationDefinition = { + name: 'Moengage Web', + slug: 'actions-moengage-web', + mode: 'device', + + settings: { + // Add any Segment destination settings required here + }, + + initialize: async ({ settings, analytics }, deps) => { + await deps.loadScript('https://cdn.moengage.com/webpush/moe_webSdk.min.latest.js') + + await deps.resolveWhen(() => window?.moengage != null, 100) + + return window?.moengage + }, + + actions: { + trackEvent + } +} + +export default browserDestination(destination) diff --git a/packages/browser-destinations/destinations/moengage-web/src/trackEvent/__tests__/index.test.ts b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/__tests__/index.test.ts new file mode 100644 index 00000000000..d254ff27765 --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/__tests__/index.test.ts @@ -0,0 +1,6 @@ +import { Analytics, Context } from '@segment/analytics-next' +import { destination } from '../../index' + +describe('Src.trackEvent', () => { + // TODO: Test your action +}) diff --git a/packages/browser-destinations/destinations/moengage-web/src/trackEvent/generated-types.ts b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/generated-types.ts new file mode 100644 index 00000000000..944d22b0857 --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/generated-types.ts @@ -0,0 +1,3 @@ +// Generated file. DO NOT MODIFY IT BY HAND. + +export interface Payload {} diff --git a/packages/browser-destinations/destinations/moengage-web/src/trackEvent/index.ts b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/index.ts new file mode 100644 index 00000000000..38af05226aa --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/src/trackEvent/index.ts @@ -0,0 +1,16 @@ +import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types' +import type { Settings } from '../generated-types' +import type { Payload } from './generated-types' + +// Change from unknown to the partner SDK types +const action: BrowserActionDefinition = { + title: 'Track Event', + description: '', + platform: 'web', + fields: {}, + perform: (_client) => { + // Invoke Partner SDK here + } +} + +export default action diff --git a/packages/browser-destinations/destinations/moengage-web/tsconfig.json b/packages/browser-destinations/destinations/moengage-web/tsconfig.json new file mode 100644 index 00000000000..c2a7897afd6 --- /dev/null +++ b/packages/browser-destinations/destinations/moengage-web/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "rootDir": "./src", + "baseUrl": "." + }, + "include": ["src"], + "exclude": ["dist", "**/__tests__"] +}