Skip to content

Commit c32181d

Browse files
committed
Implement logToConsole plugin
1 parent 0a1e6de commit c32181d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export { logToConsole } from './logToConsole';
12
export { normalizePrezlyMetaPlugin } from './normalizePrezlyMeta';
23
export { sendEventToPrezlyPlugin } from './sendToPrezly';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-disable no-console */
2+
import type { Context, Plugin } from '@segment/analytics-next';
3+
4+
import { stringify } from '../lib';
5+
import { version } from '../version';
6+
7+
export function logToConsole(): Plugin {
8+
async function apply(ctx: Context) {
9+
const { type, userId, previousId, traits, category, name, properties, event } = ctx.event;
10+
11+
if (type === 'identify') {
12+
console.log(`analytics.identify(${stringify(userId, traits)})`);
13+
}
14+
15+
if (type === 'alias') {
16+
console.log(`analytics.alias(${stringify(userId, previousId)})`);
17+
}
18+
19+
if (type === 'page') {
20+
console.log(`analytics.page(${stringify(category, name, properties)})`);
21+
}
22+
23+
if (type === 'track') {
24+
console.log(`analytics.track(${stringify(event, properties)})`);
25+
}
26+
27+
return ctx;
28+
}
29+
30+
return {
31+
name: 'Log events to console',
32+
type: 'after',
33+
version,
34+
35+
isLoaded: () => true,
36+
load: () => Promise.resolve(),
37+
38+
alias: apply,
39+
group: apply,
40+
identify: apply,
41+
page: apply,
42+
track: apply,
43+
};
44+
}

0 commit comments

Comments
 (0)