Enable website tracking

Abstract

Learn how to connect your website using a plugin, the JSS library, or the PHP library.

Sitecore Send lets you record the actions your users perform on your website and connect these actions with campaigns for the ultimate personalization experience. You can also add forms to your website pages and fine-tune when they will appear.

To add a website:

  1. On the Dashboard, on the top right corner, click Account, and click Websites.

    The first time you visit the Tracked Websites page, you must enter your website's domain. Whenever you revisit the page it will contain a list of the websites that you have already added.

  2. Click Add website.

  3. In the Website domain field, enter your domain and click Submit.

To connect your website using our platform's plugin:

  1. Click Install connection script.

  2. Navigate to the plugin that you want to use and click Install.

If you have a custom installation or if your favorite platform is not available on our plugin list, you can chose to install the JSS or PHP tracking library.

JSS tracking library

If your website requires a JSS tracking library, you can install the website JSS tracking library by using our configuration examples. You can copy and paste the appropriate code snippet into your website HEAD tag.

To connect your website using the JSS tracking library:

  1. Click Install connection script.

  2. Navigate to Custom installation and click Install.

  3. Click </>Copy to copy the script.

    There are various examples on this page on how to identify your visitors, track page view events, track item added to cart, track order completed events, and track product view events.

PHP tracking library

If your website requires a PHP tracking library, you can install website tracking by using the PHP tracking library including the configuration examples..

To install website tracking using the PHP tracking library:

  1. Add a local, per-project dependency to your project using Composer:

    composer require sitecoresend/website-tracking
  2. Create an instance of the Tracker and perform initialization. The init phase deals with some cookies that determines if current user is a new visitor or a returned visitor.

    <?php
    
    $siteId = 'some-site-id';
    $trackerFactory = new SitecoreSend\TrackerFactory();
    $tracker = $trackerFactory->create($siteId);
    
    $tracker->init($siteId);
  3. To identify visitors:

    <?php
    
    $tracker->identify('some@mail.com');
    // identify with email and name
    // commented out as you need to choose one of these calls only
    // $tracker->identify('john@doe.com', 'John Doe');
    
    // You can also check if a user is already identified
    $tracker->isIdentified('john@doe.com'); // returns a boolean
  4. To track page view events:

    <?php
    
    $tracker->pageView('https://example.com');
  5. To track an item added to a cart:

    <?php
    
    // mandatory - a unique code for the product, for example, it's SKU
    $itemCode = 'COW-T-SHIRT';
    // mandatory - the price of the product
    $itemPrice = 12.02;
    // mandatory - the URL to get to the relevant product page
    $itemUrl = 'http://your.store/product-101';
    // mandatory
    $itemQuantity = 2;
    // mandatory - the total price for purchasing the given quantity of this product 
    $itemTotalPrice = 24.04;
    // mandatory - the name / title of this product
    $itemName = 'Cow T-Shirt'; // mandatory
    // mandatory - the image URL of this product
    $itemImage = 'http://your.store/product-color-blue.jpg';
    // optional - the category of this product
    $itemCategory = 'T-Shirts';
    // optional - the manufacturer, brand name or company / owner of this product (if any) 
    $itemManufacturer = 'Acme Co';
    
    // you can add custom properties and use them later on in segmentations or automations
    // You can track things like the category or the manufacturer of the t-shirt in this case
    
    $extraProps = array(
      "itemCategory" => $itemCategory,
      "itemManufacturer" => $itemManufacturer
    );
    
    // Tracking add to cart events with mandatory arguments
    $tracker->addToOrder($itemCode, $itemPrice, $itemUrl, $itemQuantity);
    
    // Tracking add to cart events with mandatory arguments + optional
    $tracker->addToOrder($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage, $extraProps);
  6. To track order completed events:

    <?php
    
    // mandatory - a unique code for the product, for example, it's SKU
    $itemCode = 'COW-T-SHIRT';
    // mandatory - the price of the product
    $itemPrice = 12.02;
    // mandatory - the URL to get to the relevant product page
    $itemUrl = 'http://your.store/product-101';
    // mandatory 
    $itemQuantity = 2;
    // mandatory - the total price for purchasing the given quantity of this product 
    $itemTotalPrice = 24.04;
    // mandatory - the name / title of this product
    $itemName = 'Cow T-Shirt';
    // mandatory - the image URL of this product
    $itemImage = 'http://your.store/product-color-blue.jpg',
    // optional - the category of this product 
    $itemCategory = 'T-Shirts';
    // optional - the manufacturer, brand name or company / owner of this product (if any) 
    $itemManufacturer = 'Acme Co';
    
    // You can track things like the category or the manufacturer of the t-shirt in this case
    
    $extraProps = array(
    
    "itemCategory" => $itemCategory,
    "itemManufacturer" => $itemManufacturer
    
    );
    
    //order completed
    $order = $tracker->createOrder();
    
    $order->addProduct($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage, $extraProps);
    //add as many products as you want before tracking and order completed event
    $order->addProduct($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage, $extraProps);
    
    $tracker->orderCompleted($order);
  7. To track product view events:

    <?php
    
    $properties = array(
      array(
            "product"   =>     array(
                 "itemCode" => "COW-T-SHIRT",
                  "itemPrice" => 12.02,
                  "itemUrl" => "http://your.store/product-101",
                  "itemQuantity" => 2, 
                  "itemTotal" => 24.04,
                  "itemImage" => "http://your.store/product-color-blue.jpg",
                  "itemName" => "Cow T-Shirt",
                  "itemDescription" => "Some Product Description",
                  // optional - the category of this product
                  "itemCategory" => "T-Shirts",
                  // optional - the manufacturer, brand name or company / owner of this product (if any)
                  "itemManufacturer" => "Acme Co"
             )
        )
    );
    
    $tracker->pageView('https://example.com', $properties);