Universal Segment
  • 02 Aug 2024
  • 9 Minutes to read
  • Dark
    Light

Universal Segment

  • Dark
    Light

Article summary

The Universal segment is a JavaScript tag. This tag is able to detect the URL of the page it is implemented on, and the URL detection capability can be leveraged to create different segments based on the URL. Additional custom variables can be leveraged to extract additional data from the website to build more granular segments.

Each segment will share the same JavaScript tag for the entire buyer account.

Universal segment settings

When using Universal segment, you can configure custom variables that can be then used in your segment to determine if the user belongs to that segment based on information provided by the website. Those variables need to be set up beforehand, so you can select them in the conditions section of your Universal segment.

  1. In the left menu, click Data and select Segments.
  2. In the upper right-hand corner, click Universal Segment Settings.

There are 2 types of custom variables:

  • String: Using this type, Samsung DSP will expect the value passed to that variable to contain any sequence of characters. Ex: Hello World. Targeting rules for strings will contain operators such as "contains", "starts with", or "ends with".
  • Integer: Using this type, Samsung DSP will expect the value passed to that variable to be a whole number, without fraction/decimals. Ex: 10. Targeting rules for integers will contain operators such as "greater than" or "less than".

Once set up, you can now create a universal segment using the custom variables you defined.

Create a Universal Segment

  • In the left menu, click Data and select Segments.
  • In the upper right-hand corner, click +New Segment and select Universal Segment.
  • Fill in out the following form and click Create to finish.

General Settings

  • Name: Enter a name for your segment.
  • Expiry: Enter an expiry time for the retargeting. Ex: 15 days, means that if we don’t see that user again after 15 days, that user will no longer be part of that segment.
  • Description: Enter a description of the segment.
  • Universal Tag conditions: This is where you set up the conditions for the segment to be triggered. By default, only the URL of the page where the segment is implemented would be available. You can choose different matching conditions on the URL, such as contains, exact match, etc. Once you’ve set up custom variables, those variables will also appear as conditions, and the matching conditions will depend on the type of custom variables you have set up.

Piggyback HTML

This is if you want to include HTML/JavaScript code that will also be triggered at the same time as the segment. This would be useful if you want to call other pixels at the same time.

In the piggyback HTML field, you can also include the following macros:

MacroTypeDescription
__AG_URL__stringThe URL passed to the universal tag, either manually (in the __AG variable) or automatically.
__AG_REV__numberThe revenue number passed to the universal tag (in the __AG variable).
__AGDATA[name]__string or numberAny variable set in the __AGDATA JavaScript variable. Replace name with the name of the variable.

Copy/Download a Universal tag

  • On the segment row, click the three dots located in the Actions column:
    • Select Copy Tag to copy the tag in your clipboard.
    • Select Download Tag to download a .txt file containing the pixel/tag.

All Universal segments will use the same code/tag so you don’t need to copy/download it for each segment.

Implement a Universal tag

The Samsung DSP universal segment tag can be placed directly on a webpage or in the tag manager.

Below is an example of a Universal Segment tag:

    <script type="text/javascript">
      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };
    </script>
    <script type="text/javascript" src="//cdn.adgrx.com/usegments/XXXX/yy.js" async="true"></script>

Tag Managers

Click here to expand
Tag ManagerTypeImplementation Notes
Google Tag ManagerCustom HTML

Paste the entire code provided by Samsung DSP. Ex:

    <script type="text/javascript">
      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };
    </script>
    <script type="text/javascript" src="//cdn.adgrx.com/usegments/XXXX/yy.js" async="true"></script>

NOTE: This does not apply to the Custom image type.

Google FloodlightDynamic tag

Paste the entire code provided by Samsung DSP. Ex:

    <script type="text/javascript">
      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };
    </script>
    <script type="text/javascript" src="//cdn.adgrx.com/usegments/XXXX/yy.js" async="true"></script>

Complete HTML Page Example

Click here to expand

When placing the universal segment tag directly into your web page HTML, it must be between <body> and </body> HTMLtags. It is recommended to place it near the bottom before the closing </body> HTML tag.

The __AGDATA JSON object is where you can provide custom information that can then be use to generate the segments in Samsung DSP. Make sure that the custom variables are setup in Samsung DSP first so that the data can be available to build the segments.

Here's a really simple example of a universal segment tag on a blank page:


    <!DOCTYPE html>
    <html>
    <head>
      <title>Samsung DSP Simple Universal Segment Tag Demo</title>
    </head>
    <body>

    	...content...

      <script type="text/javascript">
        __AGDATA = {
          advertiser_name: "Advertiser 1",
          info_1: 1234
        };
      </script>
      <script type="text/javascript" src="//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yy.js" async="true"></script>
    </body>
    </html>

Advanced examples

Javascript version

Click here to expand

In some cases, you might need to implement the tag as javascript code. See the following example:


    __AGDATA = {
      advertiser_name: "Advertiser 1",
      info_1: 1234
    };

    var SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG = document.createElement("script");
    SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("type", "text/javascript");
    SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("src", "//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yY.js");
    SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("async", "true");
    document.getElementsByTagName("body")[0].appendChild(SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG);

Implementing the tag on a button

Click here to expand

While the best and more reliable way to call tags or pixels is directly on a page or via a tag manager, it is also possible to call our tag when the user clicks on a button. We highly recommend having the tag directly on the destination page of the button, but if it's not possible to implement a tag on the destination page, here are a few examples of how to call the tag on a button.

Without a redirect or redirect that opens a new tab/window

If clicking the button does not redirect the user to another page or open up a new tab or window (e.g., <a target="_blank">), the tag should be called correctly as there is enough time for the browser to execute the javascript and call Samsung Ads DSP servers.


    <script>
    function buttonSamsungDSPTracking() {
      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };

      var SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG = document.createElement("script");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("type", "text/javascript");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("src", "//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yY.js");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("async", "true");
      document.getElementsByTagName("body")[0].appendChild(SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG);
    }
    </script>
    <a href="https://www.customer.com/page123" target="_blank" onclick="buttonSamsungDSPTracking();">button</a>

With a redirect in the same tab/window

If the button redirects the user to another page that loads in the same tab/window, you need to prevent the default redirect temporarily to allow the tag/pixel/segment call to complete prior to the redirection.

Using this technique, there is no guarantee that every tag/pixel/segment that the universal segment tag need to call will be called correctly, including the initial Samsung DSP tag. This is because depending on the connection speed of the user, 1 second might not be enough to call the Samsung DSP server and execute the necessary Javascript. You can change the timeout to a greater value, but there is still no guarantee the script will have time to execute and complete.


    <script>
    function buttonSamsungDSPTracking(pLinkObj) {
      // Prevent the redirection
      evt.preventDefault ? evt.preventDefault() : (event.returnValue = false);

      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };

      var SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG = document.createElement("script");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("type", "text/javascript");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("src", "//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yY.js");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("async", "true");
      document.getElementsByTagName("body")[0].appendChild(SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG);
      setTimeout("window.location.href ='" + pLinkObj.href + "'", 1000);
    }
    </script>
    <a href="https://www.customer.com/page123" onclick="buttonSamsungDSPTracking(this); return false;">button</a>

Alternate code: Using an event listener instead of _onclick _attribute.


    <a id="myButton" href="https://www.customer.com/page123">button</a>
    <script>
    // Cross-browsers event listener function
    function regEvent(elem, eventName, fn) {
      if(typeof elem.addEventListener != "undefined") {
        elem.addEventListener(eventName, fn, false);
        return true;
      } else if(typeof elem.attachEvent != "undefined") {
        elem.attachEvent("on"+eventName, fn);
        return true;
      } else if(typeof elem["on"+eventName] == "function") {
        var existing = elem["on"+eventName];
        elem["on"+eventName] = function() {
          existing();
          fn();
        };
        return true;
      } else {
        try { elem["on"+eventName] = fn; } catch(err) { return false; }
        return typeof elem["on"+eventName] == "function";
      }
    }

    function buttonSamsungDSPTracking(evt, pLinkObj) {
      // Prevent the redirection
      evt.preventDefault ? evt.preventDefault() : (event.returnValue = false);

      __AGDATA = {
        advertiser_name: "Advertiser 1",
        info_1: 1234
      };

      var SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG = document.createElement("script");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("type", "text/javascript");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("src", "//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yY.js");
      SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("async", "true");
      document.getElementsByTagName("body")[0].appendChild(SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG);
      setTimeout("window.location.href ='" + pLinkObj.href + "'", 1000);
    }
    regEvent(document.querySelector("#myButton"), "click", function(evt) { buttonSamsungDSPTracking(evt, this); });
    </script>

Implementing the tag on page load and a button

Click here to expand

Here's an example of an HTML page containing the universal tag, called on page load event as well as on a button click event.


    <!DOCTYPE html>
    <html>
    <head>
      <title>Samsung DSP Universal Segment Tag Demo</title>
      <script>
        // Cross-browsers event listener function
        function regEvent(elem, eventName, fn) {
          if(typeof elem.addEventListener != "undefined") {
            elem.addEventListener(eventName, fn, false);
            return true;
          } else if(typeof elem.attachEvent != "undefined") {
            elem.attachEvent("on"+eventName, fn);
            return true;
          } else if(typeof elem["on"+eventName] == "function") {
            var existing = elem["on"+eventName];
            elem["on"+eventName] = function() {
              existing();
              fn();
            };
            return true;
          } else {
            try { elem["on"+eventName] = fn; } catch(err) { return false; }
            return typeof elem["on"+eventName] == "function";
          }
        }
      </script>
    </head>
    <body>
      <button id="myButton">Click Me!</button>

      <!-- Called immediately -->
      <script type="text/javascript">
        __AGDATA = {
          event_name: "page_load"
        };
      </script>
      <script type="text/javascript" src="//cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX/yY.js" async="true"></script>

      <!-- Code that will enable the universal to be called again,
           with a different event_name when the button is clicked -->
      <script>
        function buttonSamsungDSPTracking() {
          __AGDATA = {
            event_name: "button_clicked"
          };

          var SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG = document.createElement("script");
          SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("type", "text/javascript");
          SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("src", "http://cdn.adgrx.com/usegments/xxXXXXXxxxxXXxxxxXXXXxxxxxxxxXX=/yY.js");
          SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG.setAttribute("async", "true");
          document.getElementsByTagName("body")[0].appendChild(SAMSUNG_DSP_UNIVERSAL_SCRIPT_TAG);
        }

        // Here, we are using the regEvent function we have defined in the <head>, but you
        // can use your own function to setup the event listener (ex: jQuery.click)
        regEvent(document.querySelector("#myButton"), "click", buttonSamsungDSPTracking);
      </script>
    </body>
    </html>

Data Parameters

Override URL

By default, the URL of the page is automatically detected by the universal segment tag. However, you can optionally override that URL.

It's useful to override the auto-detection when you know that the universal segment tag is being placed in an IFRAME where it is unable to detect the true/top URL of the page. If you include the universal segment into a Google’s Floodlight tag, it will be inside the Floodlight iframe so it would be important to override the URL detection in this case.

To do so, simply create a JSON object called __AG and with a key named url as shown below.


    <script type="text/javascript">
      __AG = {
          url: "http://www.trueurlgoeshere.com/thepage.html"
      };
    </script>
    <... rest of universal segment tag goes here or further below ...>

Code showing an HTML tree when an iframe is involved


    <!DOCTYPE html>
    <html>
    <head>
      <title>Samsung DSP Simple Universal Segment Tag Demo</title>
    </head>
    <body>

    	...content...

        <iframe src="https://mysite.com/myiframe.html">
            <script type="text/javascript">
              __AG = {
                url: "http://www.trueurlgoeshere.com/thepage.html"
              };
            </script>
            <... rest of universal segment tag goes here or further below ...>
        </iframe>

    </body>
    </html>

Revenue (conversion)

Optionally, it is possible to pass in the "revenue" generated from a conversion into the universal segment tag. This allows Samsung DSP to report on conversion revenue.

To do so, simply create a JSON object called __AG and with a key named revenue as shown below.


    <script type="text/javascript">
      __AG = {
          revenue: 1.25
      };
    </script>
    <... rest of universal segment tag goes here or further below ...>

Simultaneously Overriding the URL and adding the revenue

To do so, ensure that the JSON object has both the revenue and url key.


    <script type="text/javascript">
      __AG = {
          revenue: 1.25,
          url: "http://www.trueurlgoeshere.com/thepage.html"
      };
    </script>
    <... rest of universal segment tag goes here or further below ...>

Complete HTML Page Example

Click here to expand

Here's an example of a universal segment tag on a blank page:


    <!DOCTYPE html>
    <html>
    <head>
      <title>Samsung DSP Simple Universal Segment Tag Demo</title>
    </head>
    <body>

      ...content...

      <script type="text/javascript">
        __AGDATA = {
          advertiser_name: "Advertiser 1",
          info_1: 1234
        };
        __AG = {
          revenue: 1.25,
          url: "http://www.trueurlgoeshere.com/thepage.html"
        };
      </script>
      <script type="text/javascript" src="//cdn.adgrx.com/usegments/XXXX/yy.js" async="true"></script>
    </body>
    </html>

View Segments Activity (Reporting)

  • Click the three dots and select Segments under Reports or Real-Time section.

Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.