# How to track referrer as a tag in Retreaver.js?

In order to track the website your visitors are coming from as tags you'll need to use the ['advanced' code block for Retreaver.js](https://help.retreaver.com/hc/en-us/articles/360000566863).

The first step is getting the referring URL. This example will fetch the directly referring URL using [document.referrer](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) and save just the domain part ("google.com", "bing.com") as a tag using  [add\_tags](https://retreaver.com/documentation/javascript/v1/Retreaver.Number.html):

```
Retreaver.configure({
        host: 'api.routingapi.com',
        prefix: document.location.protocol == 'https:' ? 'https' : 'http'
    });

    var campaign = new Retreaver.Campaign({campaign\_key: 'YOUR\_CAMPAIGN\_KEY'});

    // Get the referrer domain, for ex: 'google.com', 'bing.com', etc
    function referrerDomain() {
        var url = domain.referrer;
        return url.split('/')\[2\];
    }
    campaign.request\_number(function (number) {
        // Store referrer domain as a tag
        number.add\_tags({
            referrer: referrerDomain(),
        });
    });
```

**Note:** A more advanced implementation might want to track the original referring URL as a cookie as soon as the visitor arrives to your website. This allows the user to visit other parts of your website before reaching a particular landing page, while still keeping track of the source URL.
