Opencart: Add store based google analytics code

Posted: June 8, 2013 by Sankar Vijayakumar in OpenCart, Php
Tags: , , , , ,
How to add separate google analytics code for each store?

Here’s it, just 3 files need to be modified:

  1. admin\controller\setting\store.php
    After “$this->data[‘entry_secure’] = $this->language->get(‘entry_secure’);” add:

    $this->data['entry_google_analytics'] = $this->language->get('entry_google_analytics');

    Before “$this->template = ‘setting/store_form.tpl’;” add:

    if (isset($this->request->post['config_google_analytics'])) {
    $this->data['config_google_analytics'] = $this->request->post['config_google_analytics'];
    } elseif (isset($store_info['config_google_analytics'])) {
    $this->data['config_google_analytics'] = $store_info['config_google_analytics'];
    } else {
    $this->data['config_google_analytics'] = '';
    }

  2. admin\language\english\setting\store.php
    Add:

    $_['entry_google_analytics'] = 'Google Analytics Code:<br /><span class="help">Login to your <a href="http://www.google.com/analytics/" target="_blank"><u>Google Analytics</u></a> account and after creating your web site profile copy and paste the analytics code into this field.</span>';

  3. admin\view\template\setting\store_form.tpl
    Inside the div with id=”tab-server” add:

    <tr>
    <td><?php echo $entry_google_analytics; ?></td>
    <td>
    <textarea name="config_google_analytics" cols="40" rows="5"><?php echo $config_google_analytics; ?></textarea>
    </td>
    </tr>

Now go to settings and add google analytics code in the “Server” tab of your store.
Happy Coding 😀 !!

Comments
  1. I have a module to opencart, http://oficinadopixel.com.br/trackeando-seu-opencart-com-o-google-analytics. Have tracking and send orders to Google analytics, is free too 🙂

    Like

  2. pmsfddavid says:

    Thanks for your share !

    Like

  3. rajbir says:

    if i paste the code in settings system . which file does it go in

    Like

How's it? Your comments and suggestions...