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

    $_['entry_google_analytics'] = 'Google Analytics Code:<br /><span class="help">Login to your <a href="" 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:

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

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

  1. I have a module to opencart, Have tracking and send orders to Google analytics, is free too 🙂


  2. pmsfddavid says:

    Thanks for your share !


  3. rajbir says:

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


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

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s