How to attach context to analytics events
<p>I was looking to gather some of your collective wisdom in relation to analytics.</p>

<p>Here is an example to illustrate the issue:</p>

<blockquote>
  <p>A user opens the application and starts a session.  They open <strong>database A</strong> and perform <strong>action X</strong>.  They then open <strong>database B</strong> and perform <strong>action X</strong> again.</p>
</blockquote>

<p>We are tracking an event every time someone does <strong>action X</strong>.  </p>

<p>We can easily see that, in this session, <strong>action X</strong> was performed twice.  However, we would like to know that <strong>action X</strong> was performed once <em>in the context of</em> <strong>database A</strong> and once <em>in the context of</em> <strong>database B</strong>.  This would mean we could filter <strong>action X</strong> events by the database that was being used at the time they were made.</p>

<p>I can think of two approaches:</p>

<ol>
<li><p>Attach the current database name (and any other context) to the event each time it is fired.  However, this seems wasteful as each event could end up piggy-backing a lot of context around.</p></li>
<li><p>Send events when the database is changed and somehow infer from the chronology which database was open at the time each <strong>event X</strong> is sent.  This approach is less wasteful but will make analysis more difficult.</p></li>
</ol>

<p>Which approach would you suggest?  Are there any other approaches?</p>