Sending Data to Segment

Avatar
by Jeff Richmond
Follow

With Skilljar, you can send student registration, student activity, and training activity data directly to Segment. The benefits include:

  • Automatically capturing student lead data, such as first name, last name, email address, job title, and more
  • Adding training activity (registrations, completions, etc.) and a 360 degree view of your lead (training plus other data).

(Learn more about marketing your training in our eBook: How to Market Customer Training)

The easiest way to send data to Segment is via our Javascript based events available in the Theming area of your dashboard. We call Segment's Analytics.js library to add leads and training data. This can be done without any developer involvement.

You will need:

  • Your Segment project’s Write Key, which you can find in your Segment project setup guide or settings.

Installing Segment Analytics.js

In the Global Head Snippet, add the general Segment Analytics.js code snippet to load their tracking library. The code within the Global Head Snippet loads on every page.

  • IMPORTANT: Before adding the snippet below, you’ll need to replace YOUR_WRITE_KEY with your Segment project’s Write Key, which you can find in your project setup guide or settings.
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
analytics.load("YOUR_WRITE_KEY");
analytics.page();
}}();
</script>

Note: This tag also starts to track course catalog page views with the analytics.page call.

Identifying and Tracking Skilljar Students 

This code snippet would be added directly below the above code snippet to add functionality that calls the Analytics.identify endpoint to create users in Segment when they are created in Skilljar. Once Skilljar makes a call to identify a user in Segment, further calls can be made to track user activity down the line.

In the Global Code Snippet, paste the following code to start identifying users:

<script>
analytics.ready(function() {
if(typeof skilljarUser !== 'undefined'){
if(!analytics.user().traits().email){analytics.identify({'name': skilljarUser.name,'email':skilljarUser.email})};
}
});
</script>

If applicable, you can add any custom sign up field information you are capturing about your Skilljar users to the Analytics.identify call, attaching the information to the Segment user as well. To do this, replace SIGN-UP-FIELD in the code below with your exact custom sign up field names.

<script>
analytics.ready(function() {
if(typeof skilljarUser !== 'undefined'){
if(!analytics.user().traits().email){analytics.identify({'name': skilljarUser.name,'email':skilljarUser.email,'SIGN-UP-FIELD':skilljarUserSignupFields['SIGN-UP-FIELD'].value})};
}
});
</script>

If you have multiple sign-up fields, you can add them in the same format, separated by a comma.

 

Sending Course Enrollment Events

In the Conversion Code Snippet, paste the following code to start tracking the Course Enrollment event. The code within the Conversion Code Snippet only loads upon the enrollment or purchase of a course.

<script>
if (typeof(skilljarCourse) !== 'undefined') {analytics.track('Course Registered',{'course_id':skilljarCourse.publishedCourseId,'course_title':skilljarCourse.title})}
</script>

 

Sending Course Completion Events

In the Completion Code Snippet, paste the following code to start tracking the Course Completion event. The Completion Code Snippet only loads upon the completion of a course.

<script>
if (typeof(skilljarCourse) !== 'undefined') {analytics.track('Course Completed',{'course_id':skilljarCourse.publishedCourseId,'course_title':skilljarCourse.title})}
</script>

 

Sending Lesson Completion to Segment

In the Global Code Snippet, paste the following code to start tracking lesson progress:

<script>
if(typeof skilljarCourse !== 'undefined'){
if (typeof(skilljarCourse.lesson) !== 'undefined' && $('.lesson-quiz .lesson-active').length == 0 && document.domain != 'dashboard.skilljar.com') {analytics.track('Lesson Completed',{'course_id':skilljarCourse.publishedCourseId,'course_title':skilljarCourse.title,'lesson_id':skilljarCourse.lesson.id,'lesson_title':skilljarCourse.lesson.title});var total_lessons = $('#curriculum-list-2 a').length;var completed_lessons = $('#curriculum-list-2 a.lesson-complete').length;var lesson_progress = (completed_lessons/total_lessons).toFixed(2);analytics.track('Course Progress Update',{'course_id':skilljarCourse.publishedCourseId,'course_title':skilljarCourse.title,'course_progress': Number(lesson_progress)})}
}
</script>

 

Using Skilljar Data in Segment

Once you are successfully passing Skilljar data to Segment, you will be able to send this information along to your Destinations which you have set up in Segment

You can confirm that Skilljar Events are passing through your Segment instance by viewing the Debugger and completing some actions as a student on a domain which has your tracking enabled:

Screen_Shot_2019-04-09_at_3.24.34_PM.png

Powered by Zendesk