Skip to content

aveprikov/segmentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Segmentation

JS segmentation library for split tests

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

Files

  • segmentator.js is a complete ES6 version, easy to modify according to your needs
  • segmentator.min.js is a minified version for easy use

Parameters

Method

/**
 * Get segment
 * @params {segments_number {integer}, prefix {string}, days {integer}}
 * @returns {string}
*/

segmab({params}, callback);

Params

Number of segments
  • segments_number, integer (from 2 to 26)
Prefix
  • prefix, string
Cookie's lifetime (days)
  • days, non-zero integer

Usage

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

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

Getting the segment value into an external variable:

const segment = segmab({segments_number: 3, prefix: "myprefix", days: 1});
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:

segmab({segments_number: 3, prefix: "myprefix", days: 365}, segment => {
    ga("set", "dimension1", segment);
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors