---
title: "Install website tracking"
slug: "install-website-tracking"
abstract: "How to install website tracking using available plugins, or inserting tracking code snippets from the JS or PHP tracking libraries."
---
# Install website tracking

You can install website tracking by using the available Sitecore Send plugins or by inserting the tracking code snippets into specific sections of your website. If you have a custom installation or if your favorite platform is not available on our plugin list, you can choose to install the JS or PHP tracking library.

Before you begin installing website tracking, ensure that you have [added your website](https://doc.sitecore.com/send/en/users/sitecore-send/website-tracking/add-or-delete-a-website.html "Add or delete a website") to your Sitecore Send account.

## Install website tracking using a plugin

Sitecore Send supports website tracking plugins that let you track the website behavior of your visitors, ghost users, and logged-in users.

To install website tracking using a plugin:

1. On the menu bar, click **More** > **Websites**.
2. Click the **URL** of the website that you want to track.

    On the **Connect your website** page, you can see your **Website domain** and **[website ID](https://doc.sitecore.com/send/en/users/sitecore-send/website-tracking/add-or-delete-a-website.html#UUID-3d2620fc-709f-7eab-2666-272839db128e_section-idm4625920324608033503058981726 "Add a website")**.

3. Click **Install connection script**.
4. Navigate to the plugin that applies to your website and click **Install**.

## Install website tracking using the JS tracking library

If your website requires a JS tracking library, you can install the website JS tracking library by using our code snippets. You can copy and paste the appropriate code snippets into your website `HEAD` tag.

> [!important]
> Make sure you replace any placeholder [website ID](https://doc.sitecore.com/send/en/users/sitecore-send/website-tracking/add-or-delete-a-website.html#UUID-3d2620fc-709f-7eab-2666-272839db128e_section-idm4625920324608033503058981726 "Add a website"), website, email address, item code, price, and product details in the code snippets with actual information.

To install website tracking using the JS tracking library:

1. On the menu bar, click **More** > **Websites**.
2. Click the **URL** of the website you want to track.

    On the **Connect your website** page, you can see your **Website domain** and **Your website id**.

3. Click **Install connection script**.
4. Navigate to **Custom installation** and click **Install**.
5. Click **</> Copy** to copy the script for loading and initializing the tracker:

    ```xml
    <script>
    //load TrackerJS
    !function(t,n,e,o,a){function d(t){var n=~~(Date.now()/3e5),o=document.createElement(e);o.async=!0,o.src=t+"?ts="+n;var a=document.getElementsByTagName(e)[0];a.parentNode.insertBefore(o,a)}t.MooTrackerObject=a,t[a]=t[a]||function(){return t[a].q?void t[a].q.push(arguments):void(t[a].q=[arguments])},window.attachEvent?window.attachEvent("onload",d.bind(this,o)):window.addEventListener("load",d.bind(this,o),!1)}(window,document,"script","//cdn.stat-track.com/statics/moosend-tracking.min.js","mootrack");
    //tracker has to be initialized otherwise it will generate warnings and wont sendtracking events
    mootrack('init', 'Paste your website ID here');
    </script>
    ```

6. To track different types of information, paste the corresponding code:

    To accurately track an ORDER_COMPLETED event, the corresponding ADDED_TO_ORDER event for the same product must be recorded first. This means the user needs to add the product to their basket before completing the purchase.

    - To identify visitors:

        ```

        // identify with email
        mootrack('identify', 'john@doe.com');

        // identify with email and name
        // commented out as you need to choose one of these calls only
        //mootrack('identify', 'john@doe.com', 'John Doe');
        ```

    - To track page view events:

        ```

        // track a view of the current page
        mootrack('trackPageView');
        ```

    - To track an item added to a cart:

        ```csharp
        // mandatory - a unique code for the product, like its SKU
        var itemCode = 'COW-T-SHIRT';
        // mandatory - the name / title of this product
        var itemName = 'Cow T-Shirt';
        // mandatory - the image url of this product
        var itemImage = 'http://your.store/product-color-blue.jpg';
        // mandatory - the price of this product
        var itemPrice = 12.02;
        // mandatory - the url to get to the relevant product page
        var itemUrl = 'http://your.store/product-101';
        // mandatory
        var itemQuantity = 2;
        // mandatory - the total price for purchasing the given quantity of this product
        var itemTotalPrice = 24.04;
        // optional - the category of this product
        var itemCategory = 'T-Shirts';
        // optional - the manufacturer, brand name or company / owner of this product (if any)
        var itemManufacturer = 'Acme Co';
        // optional - the supplier of this product (if any)
        var itemSupplier = 'Supplier Co';
        // Tracking add to cart events with mandatory arguments
        mootrack('trackAddToOrder', itemCode, itemPrice, itemUrl, itemQuantity, itemTotalPrice, itemName, itemImage);
        // Tracking add to cart events with mandatory arguments + optional
        mootrack('trackAddToOrder', itemCode, itemPrice, itemUrl, itemQuantity, itemTotalPrice, itemName, itemImage, {
         itemCategory: itemCategory,
         itemManufacturer: itemManufacturer,
         itemSupplier: itemSupplier
        });
        ```

    - To track order completed events:

        ```csharp
        // send order completed events
        var product1 = {
            // mandatory - a unique code for the product, like its SKU
            itemCode: 'COW-T-SHIRT',
            // 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',
            // mandatory - the price of this 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,
            // 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',
            // optional - the supplier of this product (if any)
            itemSupplier: 'Supplier Co',
           };

        // Products should be an array with an object like product.
        var products = [product1, product2, ....];
        mootrack('trackOrderCompleted', products);
        ```

    - To track product view events:

        ```csharp
        var product1 = {
            // mandatory - a unique code for the product, like its SKU
            itemCode: 'COW-T-SHIRT',
            // 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',
            // mandatory - the price of this 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,
            // 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',
            // optional - the supplier of this product (if any)
            itemSupplier: 'Supplier Co',
          };

        // Product should be sent back as an array with an object which includes the product above
        var productInfo = [{ product: product1 }];
        mootrack('PAGE_VIEWED', productInfo);
        ```

    - To track a custom event relevant to your business:

        You can use a single line of tracking code. For example, if you want to track an event when a video is played and its properties, you can use a code like the following (event’s name character limit is 50 characters):

        ```text
        mootrack('Video Played', { "Video length": 123, "id": "h17gQr0" });
        ```

## Install website tracking using the PHP tracking library

If your website requires a PHP tracking library, you can install website tracking by using our code snippets.

> [!important]
> Make sure you replace any placeholder [website ID](https://doc.sitecore.com/send/en/users/sitecore-send/website-tracking/add-or-delete-a-website.html#UUID-3d2620fc-709f-7eab-2666-272839db128e_section-idm4625920324608033503058981726 "Add a website"), website, email address, item code, price, and product details in the code snippets with actual information.

To install website tracking using the PHP tracking library:

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

    ```text
    composer require sitecoresend/website-tracking
    ```

2. Create an instance of the tracker and perform initialization. The `init` phase deals with some cookies that determine if current user is a new visitor or a returned visitor.

    ```

    <?php

    $siteId = 'Paste your website ID here';
    $trackerFactory = new SitecoreSend\TrackerFactory();
    $tracker = $trackerFactory->create($siteId);

    $tracker->init($siteId);
    ```

3. To track different types of information, paste the corresponding code:

    To accurately track an ORDER_COMPLETED event, the corresponding ADDED_TO_ORDER event for the same product must be recorded first. This means the user needs to add the product to their basket before completing the purchase.

    - 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
        ```

    - To track page view events:

        ```

        <?php

        $tracker->pageView('https://example.com');
        ```

    - 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 track things like the category or the manufacturer of the t-shirt in this case

        // Tracking add to cart events with mandatory arguments
        $tracker->addToOrder($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage);

        // Tracking add to cart events with mandatory arguments + optional
        $tracker->addToOrder($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage, [
            "itemCategory" => $itemCategory,
            "itemManufacturer" => $itemManufacturer
        ]);
        ```

    - 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

        //order completed
        $order = $tracker->createOrder();

        $order->addProduct($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage);
        //add as many products as you want before tracking and order completed event
        $order->addProduct($itemCode, $itemPrice, $itemUrl, $itemQuantity, $itemTotalPrice, $itemName, $itemImage);

        $tracker->orderCompleted($order);
        ```

    - 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);
        ```