Skip to content

[2.20.0] TypeError · Object is not a function on pluginResult.enrichment(pluginResult) #1011

Closed
@efstathiosntonas

Description

@efstathiosntonas
  • analytics-react-native version: 2.20.0
  • Integrations versions (if used):
  • React Native version: 0.75.4 Paper
  • iOS or Android or both? Both

Steps to reproduce

Expected behavior

Actual behavior

After upgrading to 2.20.0 I get this crash:

Object is not a function

node_modules/@segment/analytics-react-native/src/timeline.ts:79:42:

if (result === undefined) {
  return;
   } else if (key === PluginType.enrichment && pluginResult?.enrichment) {
   result = pluginResult.enrichment(pluginResult); <---- this line throws the error
  } else {
  result = pluginResult;
   }

my setup:

import { createClient, SegmentClient } from '@segment/analytics-react-native';
import Keys from 'react-native-keys';

import { InjectTraits } from '@utils/InjectTraits';

let client: SegmentClient | null = null;

function segment(): SegmentClient {
  if (!client) {
    client = createClient({
      writeKey: __DEV__ ? '' : Keys.secureFor('SEGMENT_WRITE_KEY'),
      debug: false, // __DEV__,
      flushAt: 10,
      trackAppLifecycleEvents: true
    });
    client.add({ plugin: new InjectTraits() });
  }
  return client;
}

export default segment;

InjectTraits.ts

import {
  PlatformPlugin,
  PluginType,
  SegmentEvent
} from '@segment/analytics-react-native';

/**
 * Plugin that injects the user traits to every event
 */
export class InjectTraits extends PlatformPlugin {
  type = PluginType.before;

  execute(event: SegmentEvent) {
    return {
      ...event,
      context: {
        ...event.context,
        traits: {
          ...event.context,
          ...this.analytics!.userInfo.get().traits
        }
      }
    };
  }
}

index.js

const analyticsClient = segment();

const ThemedApp = () => {
  return (
      <AnalyticsProvider client={analyticsClient}>
          <App />
      </AnalyticsProvider>
  );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions