Include everywhere in your chrome extension to patch an analytics api.

npm install analytics-include
4 downloads in the last week
6 downloads in the last month
<h1>KissMetrics in Chrome Extensions wi/kiss-include.js</h1>

<p>To use KissMetrics in Chrome Extensions, we made a script that magically patches the JavaScript api for use everywhere within Chrome Extensions. You simply include it in your background page and content scripts, and call <code>_kmq.push</code> like normal.</p>

Download the patch script right from this repository, or do <code>npm install kiss-include</code>

<h3>Important points</h3>
    To use in <strong>content scripts</strong>, you will also 
    need to include it in the background page.

    <h4>Asynchronously (recommended)</h4>
      Setup this code, and being 
      <code>push</code>'ing to <code>_kmq:</code>
    </p><pre><code>  if (typeof _kmq === 'undefined') {
    window._kmq = [];
  window._kmk = 'c168ad9f6287ggbcfe92a883fc3c8c0f904e7972';</code></pre>
      At some later point, be sure to include kiss-include.js.
      It will detect your _kmk id, and set itself up.
    <p>Include kiss-include.js before this code in your extension, and then call <code>kissInclude</code> with your <code>_kmk</code> account id:</p>
    <pre><code>  kissInclude('ioheiorfhaksjnaoiewhoasdhjf');</code></pre>
    <h4>Setting a domain</h4>
      As an extension, you might want to manually
      specify a domain like so:
    <pre><code>  window.KM_COOKIE_DOMAIN = '';</code></pre>
    <p>This code needs to be placed before the library is initialized.</p>  

<strong>Extra details on the script</strong>
<p>Wherever you include the script, it detects it's environment and responds accordingly. This script alleviates the headache associated with chrome's isolated world's - you just use the JS API as defined in the docs.</p>
<strong>Including in content scripts</strong>
<p>To work in content scripts, you need to make sure it's also included in the background page</p>
<pre><code>  //in you manifest.json:
  "content_scripts": [
        "js": [ "YourScripts.js", "kiss-include.js" ],
        "matches": [ "&lt;all_urls&gt;" ],
        "run_at": "document_start"

<strong>Including in background page:</strong>
<pre><code>  //in your background.html:
  &lt;script src="kiss-include.js"&gt;&lt;/script&gt;

<p>If you include kiss-include.js after your code, you need to use asynchronous initialization. If you include it before your code, you'll need to use direct initialization.</p>

npm loves you