Opencart: Add store based google analytics code

Posted: June 8, 2013 by Sankar 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 :D !!

About these ads
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 :)

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s