1
 
 
Account
In your account you can view the status of your application, save incomplete applications and view current news and events
February 26, 2014

The magical # [ˈɑːktoʊθɔːrp]

What is the article about?

Octothorpe is the technical term for the hash which introduces the optional fragment of an url. The fragment usually tells the browser where to position the page if an anchor tag with the name of the fragment is on that page.

But is this the only way the fragment can be used?

As you can put almost everything into the fragment it can also be used as a method to add query parameters to a page which is not sent to the server and thus can only be evaluated on the client. With this method it is possible to add state to a page without generating a new URL concerning SEO.

The case:


Sometimes it is necessary to track an interaction which at the end transitions to a new page. For example a user clicks on a product link on the product list and is immediately directed to the detail view of this product. Lets assume we want to know at which index the product was on the product list so that we can use this information to reorder the sorting on that product list in the future. To receive this information we would have to send a request to a tracking server with a specific key-value pair.

Possible solutions:


There are some solutions you could think of.

  • One way is to send a client-side tracking request before the browser transitions to the next page. This approach has one big downside: We never know if the request actually succeeded. Some browsers kill all connections before loading a different page. To handle this we could wait until the request was successful and afterwards direct the user to the detail view page. But this is just as silly as it sounds.
  • Another way is to somehow get the information to the next page and track it there. But how do we get this tracking information to the next page?
    • On one hand we could add a query parameter to the detail view page. This would result in a whole lot of different URLs for the very same product. This is not a good idea. First, it will destroy the caching mechanism of the site because each parameter added to the URL results in a new resource. And second, it will lead to a SEO problem: duplicate content.
    • On the other hand we could store the tracking information in a cookie. But then we would have problems managing the cookie values. The cookie size would increase and because they are always sent to the server we would also have an increase in traffic. Furthermore, you could get in trouble with multi tabbing because cookies aren’t stateless.

Our solution:


As you may have guessed - we store the tracking information inside the fragment. On the detail view page we extract this information, send the request and afterwards “clean up” the fragment. We decided to use the variable “t” and a json object as value.

Our link looks like this:

<a href=”/p/a-great-shoe-123456#t={‘listposition’:3}”>Shoe</a>

On body load a little javascript snippet (1) reads the fragment of the url, parses the value of variable t and sends this object to our tracking server. After this is done it removes variable t from the fragment. By doing this we make sure that if a user reloads the page or sends the link to a friend the tracking request is not sent again.

For reading and manipulating the fragment we use the open source jQuery plugin “BBQ"(http://benalman.com/projects/jquery-bbq-plugin/)

1) Snippet to extract tracking information and send it to our tracking server:

var trackingHash = $.bbq.getState('t'),
    t;
try {
    if (trackingHash) {
        t = JSON.parse(trackingHash);
        if (t) {
            sendData(t); // a function to send our data to the tracking server
            hash = $.deparam.fragment();
            delete hash.t;
            /* we do not want to create a new state in the browser so that the back button still works. */
            window.location.replace('#' + $.param(hash));
        }
    }
} catch (ignore) { }

Further use of this technique:


Of course tracking is not the only reason to add information to a new page. We also use this technique to execute a javascript function onload based on variables set in the fragment. For example, to open a layer immediately on a page or to directly switch to a tab other than the default tab and even to select the correct variation on a product detail view page.

1Comments

  • Alexandre
    12.06.2014 10:28 Clock

    Hi,

    This is a very good trick and we start using it all the time :)

    Your blog is very interesting. You should write all your article in English. I don't speak Deutch.

    Alex

Write a comment
Answer to: Reply directly to the topic

Written by

Tech-Blogger

Similar Articles

We want to improve out content with your feedback.

How interesting is this blogpost?

We have received your feedback.

Cookies erlauben?

OTTO und drei Partner brauchen deine Einwilligung (Klick auf "OK") bei einzelnen Datennutzungen, um Informationen auf einem Gerät zu speichern und/oder abzurufen (IP-Adresse, Nutzer-ID, Browser-Informationen).
Die Datennutzung erfolgt für personalisierte Anzeigen und Inhalte, Anzeigen- und Inhaltsmessungen sowie um Erkenntnisse über Zielgruppen und Produktentwicklungen zu gewinnen. Mehr Infos zur Einwilligung gibt’s jederzeit hier. Mit Klick auf den Link "Cookies ablehnen" kannst du deine Einwilligung jederzeit ablehnen.

Datennutzungen

OTTO arbeitet mit Partnern zusammen, die von deinem Endgerät abgerufene Daten (Trackingdaten) auch zu eigenen Zwecken (z.B. Profilbildungen) / zu Zwecken Dritter verarbeiten. Vor diesem Hintergrund erfordert nicht nur die Erhebung der Trackingdaten, sondern auch deren Weiterverarbeitung durch diese Anbieter einer Einwilligung. Die Trackingdaten werden erst dann erhoben, wenn du auf den in dem Banner auf otto.de wiedergebenden Button „OK” klickst. Bei den Partnern handelt es sich um die folgenden Unternehmen:
Google Inc., Meta Platforms Ireland Limited, elbwalker GmbH
Weitere Informationen zu den Datenverarbeitungen durch diese Partner findest du in der Datenschutzerklärung auf otto.de/jobs. Die Informationen sind außerdem über einen Link in dem Banner abrufbar.