Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

JS segmentation library for split tests

Source JavaScript code

Public GitHub repository

Features

  • Assigns a visitor to one of the specified segments
  • The maximum number of segments is 26, like the letters in the Latin alphabet from A to Z
  • A visitor's belonging to a segment can be specified and can last for a session or a specified number of days

Method

Code Block
languagejs
themeFadeToGrey
/**
 * Get segment
 * @params {segments_number {integer}, prefix {string}, days {integer}}
 * @returns {string}
*/

segmab({params}, callback);

Parameters

NameTypeDescription
segments_numberintergerNumber of segments (from 2 to 26)
prefixstringPrefix to use several tests at the same time
daysintegerSegment's lifetime (if zero, the segment will be assigned for the duration of the browser session)

Usage

For example, three segments with the prefix "myprefix" were defined. And the segmentation script itself is connected to the "head" as a file.

Code Block
languagexml
themeMidnight
<!DOCTYPE html>
<html>
    <head>
        <script src="js/segmentator.min.js"></script>
    </head>
    <body>
        ...
    </body>
</html>


Getting the segment value into an external variable:

Code Block
languagejs
themeFadeToGrey
const segment = segmab({segments_number: 3, prefix: "myprefix", days: 0});
switch(segment) {
    case 'A':
        // something for the segment "A" visitors
        break;
    case 'B':
        // something for the segment "B" visitors
        break;
    case 'C':
        // something for the segment "C" visitors
        break;
    default:
        // if the segment value has been reset
}

Using callback function. For example, to send a segment to Google Analytics:

Code Block
languagejs
themeFadeToGrey
segmab({segments_number: 3, prefix: "myprefix", days: 0}, segment => {
    ga("set", "dimension1", segment);
});



Column

Page Navigation

Table of Contents
maxLevel3
indent0px
stylenone




Related Pages

Filter by label (Content by label)
showLabelsfalse
showSpacefalse
sorttitle
cqllabel in ("testing","segmentation")