Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pendo] initialize pendo with segment anonymous_id #707

Open
Hitscotty opened this issue Nov 16, 2022 · 0 comments
Open

[Pendo] initialize pendo with segment anonymous_id #707

Hitscotty opened this issue Nov 16, 2022 · 0 comments

Comments

@Hitscotty
Copy link

Hitscotty commented Nov 16, 2022

When using pendo through segment, the segment anonymous id does not always reach pendo. I am not entirely sure what the issue in this library is, but it is likely related to issues: #317, #325, and #349.

It seems like the pendo integration is initialized before segment. I came to this conclusion after seeing this comment

With AJS classic, we allow users to call setAnonymousId before the library initialization.
This is important because some of the destinations will use the anonymousId during the initialization,
and if we set anonId afterwards, that wouldn’t impact the destination.

Also Ensures events can be registered before library initialization.
This is important so users can register to 'initialize' and any events that may fire early during setup.

in analytics-next library and then attempting to call setAnonymousId before segment is initialized. This change should ensure that it is flushed and create a segment anonymous id before the integrations are loaded/initialized however even after this change the pendo destination was not receiving that segment anonymous id even though it did exist.

A temporary fix for this is hooking into segments 'initialize' event and forcing the expected pendo behavior (the stuff that the pendo integration does on identify):

   // analytics.js snippet file
    analytics.setAnonymousId();

    analytics.on("initialize", function () {
      // we want to make sure that we use segments pendoified anonymous id or
      // segments user id
      var isUserAnonymous = !this._user.id();
      var id = isUserAnonymous
        ? "_PENDO_T_" + this._user.anonymousId()
        : this._user.id();

      // pendo options only requires visitor/account metadata
      var options = {};
      var visitor = Object.assign({ id: id }, this._user.traits());
      options.visitor = visitor;
      var account = Object.assign(
        { id: this._group.id() },
        this._group.traits()
      );
      options.account = account;

      // ensure that on initialize pendo will have segment data and that if
      // segment data already exists it is not overwritten
      window.pendo_options.visitor = Object.assign(
        options.visitor,
        window.pendo_options.visitor
      );
      window.pendo_options.account = Object.assign(
        options.account,
        window.pendo_options.account
      );
    }); 
    
    analytics.load()
mdellanoce added a commit to pendo-io/analytics.js-integrations-1 that referenced this issue Nov 18, 2022
mdellanoce added a commit to pendo-io/analytics.js-integrations-1 that referenced this issue Dec 6, 2022
arielsilvestri added a commit that referenced this issue Dec 6, 2022
Co-authored-by: Michael Dellanoce <michael.dellanoce@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant