Moez Bouhlel @lejenome

Here, we will add Segment support to Syteup.

Segment is “a customer data hub”. It makes it easy to integrate third-party tools (analytics, advertising,…) to your application throw an all-in-one single library.

To add Segment plugin support to Syteup, we need just 3 simple steps:

1- create plugins/segment.js plugin code file that will export the plugin module to the window object:

(function (window) {
    "use strict";
    function setupSegment(settings) { = || []; = [
        ]; = function (method) {
            return function () {
                var args =;
        for (var i = 0; i <; i++) {
            var key =[i];
  [key] =;
        } = function (key) {
            if (document.getElementById("analytics-js"))
            var script = document.createElement("script");
            script.type = "text/javascript";
   = "analytics-js";
            script.async = true;
            script.src = ("https:" === document.location.protocol ? "https://" : "http://") + "" + key + "/analytics.min.js";
            var first = document.getElementsByTagName("script")[0];
            first.parentNode.insertBefore(script, first);
        // Add a version to keep track of what's in the wild. = "2.0.9";
        // Load Analytics.js with your key, which will automatically
        // load the tools you've enabled for your account. Boosh!["write_key"]);
        // Make the first page call to load the integrations. If
        // you'd like to manually name or tag the page, edit or
        // move this call however you'd like.{ title: "Syteup" });
    window.segmentPlugin = { setup: setupSegment };

what we did is to add segment code (copied from segment tutorial) into the setupSegment function, then we export it as setup item on the plugin module which should be named segmentPlugin. As you note, the user depending write_key is read from the settings object of the plugin which will be added on the third step.

2- we add a script tag to the index.html file that will load the plugin code.

the script tag should be included in the plugins section just before js/plugins.js tag and it should be loaded on defer mode

<script defer src="plugins/segment.js"></script>

3- Finally, we add the plugin settings to the configuration file config.json

option to turn on/off the plugin inside the plugins option:

"plugins": {
    "segment": true

the plugin settings object that includes all user depending settings (here we will need the user’s write_key) on the plugins_settings option:

"plugins_settings": {
    "segment": {
        "write_key": "?????????"

All Done! we are ready to test our plugin.

Don’t be lazy, and send me a pull request with your plugins code and other patches to !