0

I want to configure segment.com properly on my site and use it to manage all other apps/tools. I already installed the segment javascript on my site and used it as the source. Now, I am pushing these to MixPanel, Facebook, Google Analytics, etc.

What code should I add if I want to track an event and/or identify a user?

For simplicity's sake, i have a landing page (site.com/landing-page) with a form. After a successful submission, it redirects to a thank you page (site.com/thank-you-page).

The default settings already track the page views, and are pushing that same event to the different tools (FB: PageView, MixPanel: Loaded a Page, etc).

But in this case, i want to track the event and capture the person's information. And i don't know what to code to add and where.

My research so far

According to this article:

The best way to track new users is in client-side javascript on the welcome page after they signup, below we’ll explain why.

So, based on that, I add the code to my thank you page. But where? Header like adding GA scripts? body tag? I can add it anywhere, but i don't know where.

Next is what code should I add?

The example from the same article above:

When a new visitor goes to their site that visitor is anonymous. As soon as the visitor connects their Facebook account, Rdio knows who they are and creates a user record.

As part of that new user record the person is assigned a userId. Let’s say the new userId is 12345. Rdio will then need to fire the following calls on the welcome page:

analytics.identify('12345',{  name:'Jake Peterson',  email:'friends@segment.com'});
analytics.track('Account Created',{  authentication:'Facebook'})

This gives me two problems: track and identify.

Track Problem

I'll start with the track. Based on how I understood this, assuming the event name i want to be added is "Downloaded PDF" then I want to store the title of it as well. It should look like this, right?

<script>
analytics.track('Downloaded PDF', {
title: 'Awesome Title'
});
</script>

Am I correct to enclose them inside <script> tags?

The tracking of an event seems a bit easier to understand that the identify part. But would love to know if i got that part right.

Identify Problem

Here, i have two questions:

  1. where does userId come from? Is it automatically generated? For example, inside my MixPanel account, i see them. Is that what i use?

  2. How do i reference to the userId? or any of the other traits I want to track in my code?

Taking from the same example above:

analytics.identify('12345',{  name:'Jake Peterson',  email:'friends@segment.com'});

If i add this exact code on my thank you page, every signup will be assigned those values: '12345', 'Jake Peterson', and 'friends@segment.com', right?

What code should I add to (1) assign them the right userId (2) and get the name and email traits from the form of the previous page.

Let's say i'm only collecting first name and email.

analytics.identify("userId"{ firstName:"firstName", email:"email"});

If I add this code to my thank you page, will it automatically assign the userId, firstName, email values of the form that was submitted? That's the part I don't understand. What code to add to dynamically push the correct data.

And i know i'm not even adding the Alias part for MixPanel yet, but i just want to understand this part and the rest (hopefully) will be easier to understand.

Community
  • 1
  • 1
aylim14
  • 49
  • 1
  • 8
  • Hey buddy - there is a lot to unpack here. Did you end up getting this sorted out? I'm happy to help (I work at Segment) but a StackOverflow post may not be the best. Let me know where you're at with this problem and we can discuss from there. Cheers~ – Mussser May 10 '19 at 20:04
  • @Mussser thanks for reaching out. I found a workaround but it's very generic and not flexible to what I had in mind. Had someone from segment help me out before, but still difficult to comprehend (from a non-technical point of view such as mine). – aylim14 May 11 '19 at 23:03
  • I'd like to be able to add events by adding some code on the site itself or maybe via GTM so it's more flexible. Goal, at least for now, is to be able to track basic (and successful) form submissions. PDF 1 download, PDF 2 download, mini email course signup, etc. All different forms on different pages. That's pretty much it. – aylim14 May 11 '19 at 23:07

0 Answers0