luke
luke

Reputation: 1578

Laravel listener only sends when I dd a variable in the class being called

I have a custom class in Laravel that tracks the analytics of my app through Segment (using this package for php: https://github.com/AltThree/Segment).

Here is a snippet of my class and a function I am calling through my listener to track a login:

class Tracking {

  private function segmentTrack(User $user, string $event, array $properties = null) {
    $segment = Segment::track([
      "userId" => $user->id,
      "event" => $event,
      "properties" => $properties
    ]);

    dd($segment);
  }

  /**
    * Handle Login tracking
    *
    * @param User $user
    * @return void
    */
  public function login (User $user) {
    $this->segmentTrack($user, "Login");
  }
}

Notice the dd in the segmentTrack function. When I run the Laravel queue and I then trigger the Tracking->login() event through my app, the listener goes off fine and with the dd function, it will send that data to Segment and I can see it in their live debugger, all is well.

However, when I remove that dd, and the listener goes off and shows as successful - the data is never seen in Segment.

Can someone tell me what i'm missing? This is my first time using the Laravel queue system so a little confused why it might not be working.

Upvotes: 0

Views: 388

Answers (1)

JasonHorsleyTech
JasonHorsleyTech

Reputation: 555

For queued jobs, use:

Segment::track($payload);

Segment::flush();

Upvotes: 1

Related Questions