Integration of Google Analytics with Hybris multi-channel suite 4.8 | Hybris 4.8 tutorial



What is Google Analytics?
Google Analytics shows you how people found your site, how they explored it, and how you can enhance their visitor experience. With this information, you can improve your website return on investment, increase conversions, and make more money on the web.
How does Google Analytics work?
Google Analytics uses a first-party cookie and JavaScript code to collect information about visitors and to track your advertising campaign data. Google Analytics anonymously tracks how visitors interact with a website, including where they came from, what they did on a site, and whether they completed any of the site's conversion goals. Analytics also keeps track of your e-commerce data, and combines this with campaign and conversion information to provide insight into the performance of your advertising campaigns.
All of this information is presented in an easy-to-read, yet thorough manner, through intuitive, visual reports. Google Analytics won't affect the performance or the appearance of your website and there are no extra files to host on your website.
With information from Google Analytics, you will be able to drive traffic more efficiently to your site, and convert that traffic more effectively.

Google Account Dashboard











 Monitor activity as it happens on your site. So, you'll immediately see what's working, and what's not. Social Has Value 
 Which channels influenced your buyers?
  
Step 3.1 - Create a Google Analytics Account
To create an Analytics account:
2.     Enter your Google Account email and password and click Sign In. If you don't have a Google Account, click Sign up now to create one.
3.     Click Sign Up.
4.     Enter your Website's URL, making sure to select either http:// or https:// from the drop-down list. Enter a nickname for this account in the Account Name field, then click Continue.
5.     Enter your contact information and click Continue.
6.     Read the Google Analytics Terms of Service. If you agree to these terms, select the Yes checkbox and click Create New Account to continue.
The Tracking Instructions page that appears contains the tracking code that you'll need to paste into each page of your site or the header page of your site.

Step 3.2 - Configure Your Profile
It's important to configure your profile in order to get the most out of your reports. To access your profile settings:
1.     In the Website Profiles table, find the profile to edit.
2.     Click Edit. The Profile Settings page appears.
3.     Click Edit on the Main Website Profile Information table.
Default page
Setting this to the default (or index) page of your site allows Google Analytics to reconcile log entries for
www.example.com and www.example.com/index.html, for example. These are in fact the same page, but are reported as two distinct pages until the Default Page setting has been configured.
E-Commerce Website
To enable e-commerce reporting and the E-Commerce Analysis report set, select Yes.

Step 3.3 - Edit the Tracking Code for Custom Website Set-Ups
The tracking code that is provided to you is designed to work with most site setups. However, there are a few scenarios that require small updates to the tracking code on each of your pages. If any of the following apply to you, follow the instructions to update your code before adding it to your pages.
Learn how to:
1.     Track multiple domains in one profile (eg. a main site as well as a secure store site)
Step 3.4 - Add the Tracking Code to your Pages
Google Analytics only tracks pages that contain the Google Analytics tracking code. You'll need to add this code to each page of your site, either manually or through the use of includes or other methods.
Google analytics is already integrated in hybris accelerator we just need to make a entry in local.properties file
google.analytics.tracking.id=UA-33485702-1

To access your tracking code:
1.     Sign in to Google Analytics.
2.     From the Analytics Settings page, find the profile for which you would like to retrieve the tracking code. Please note that tracking code is profile-specific.
3.     From that profile's Settings column, click Edit.
4.     At the top right of the Main Website Profile Information box, click Check Status.
5.     Your tracking code can be copied and pasted from the text box in the Instructions for adding tracking section.
Basic installation
Copy and paste the code segment into the bottom of your content, immediately before the </body> tag of each page you are planning to track. If you use a common include or template, you can enter it there.
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxx-x]);
  _gaq.push(['_trackPageview']);

 (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
You'll need to update the "xxxx-x" in the sample above with your own Google Analytics account number. You can access your personalized tracking code in its entirety by following the instructions in Where can I find my tracking code?
Once you've completed this step, Google Analytics will begin collecting traffic data. You'll be able to see data in your reports within 24 hours.

Step 3.5 - Create Goals and Funnels
If your website is designed to drive visitors to a particular page, such as a purchase or email signup page, you can track the number of successful conversions using goals and funnels in Google Analytics.
  • A goal is a website page a visitor reaches once she or he has made a purchase or completed another desired action, such as a registration or download.
  • A funnel represents the path that you expect visitors to take in order to reach the goal. Defining these pages allows you to see how frequently visitors abandon goals (and where they go instead) and the value of the goal.
Each profile can have up to 4 goals, with a defined funnel for each. To set up goals and funnels:
Enter Goal Information:
1.     From the Analytics Settings page, find the profile for which you will be creating goals and click Edit.
2.     Select one of the four goal slots available for that profile and click Edit.
3.     Enter the Goal URL. Reaching this page marks a successful conversion. For example, a registration confirmation page, a checkout complete page, or a thank you page.
4.     Enter the Goal name as it should appear in your Google Analytics account.
5.     Turn the goal On or Off. This selection decides whether Google Analytics should track this conversion goal at this time. Generally, you'll want to set the Active Goal selection to On.
Then, Define a funnel by following these steps:
1.     Enter the URL of the first page of your conversion funnel. This page should be a page that is common to all users working their way towards your Goal. For example, if you are tracking user flow through your checkout pages, do not include a product page as a step in your funnel.
2.     Enter a Name for this step.
3.     If this step is a Required step in the conversion process, select the checkbox to the right of the step. If this checkbox is selected, users reaching your goal page without travelling through this funnel page will not be counted as conversions.
4.     Continue entering goal steps until your funnel has been completely defined. You may enter up to 10 steps, or as few as a single step.



Finally, configure Additional settings by following the steps below:
1.     If the URLs entered above are Case sensitive, select the checkbox.
2.     Enter a Goal value. This is the value used in Google Analytics' ROI calculations, and can be either a set value for the page, or a dynamic value pulled from your e-commerce receipt page. If the former, enter the amount in the field; if the latter, leave this field blank and refer to How do I track e-commerce transactions?
3.     Select a Match Type. There are three different Match Types you may select for your goal: Exact, Head, or Regular Expression.
a.     Exact Match: This option requires that the URLs entered as your funnel and goal URLs exactly match the URLs shown in the reports. For example, there can be no dynamic session identifiers or query parameters. Note: If you are using an exact match for a goal (i.e. http://domain.com/page.html), any trailing spaces will cause the goal to be invalid. If you are using partial matching (i.e. ^/page.html), trailing spaces are not an issue.
b.     Head Match: If your website has dynamically generated content, use the Head Match filter and leave out the unique values. For example, if the URL for a particular user is http://www.example.com/checkout.cgi?page=1&id=9982251615 but the id varies for every other user, enter http://www.example.com/checkout.cgi?page=1 and select Head Match as your match type.
c.     Regular Expression Match: This option uses regular expressions to match your URLs. This is useful when the stem, trailing parameters, or both can vary between users. For example, if a user could be coming from one of many subdomains, and your URLs use session identifiers, use regular expressions to define the constant element of your URL. For example, page=1 will match "http://sports.example.com/checkout.cgi?page=1&id=002" as well as "http://fishing.example.com/checkout.cgi?page=1&language=fr&id119."
d.     Click Save Changes to create this Goal and funnel, or Cancel to exit without saving.

Please see the following articles for more information on setting up goals:
Google Analytics provides the ability to add any number of users to your account, and to grant varying levels of access to your reports..
Granting profile access
To allow access to another user, follow the instructions below. Please note that additional users will need to create a free Google Account in order to be granted access.
1.     Click Access Manager.
2.     Click Add.
3.     Enter the user's email address, last name, and first name.
4.     Select the Access type for this user: View reports only, or Account Administrator, which allows the user to edit account settings.
5.     If you selected View reports only, select the profiles to which this user should have access (note that Account Admins have access to all profiles). Reports for profiles that are not selected will not be available to this user.
6.     Click Add to move these profiles into the Selected Website Profiles list.
7.     Click Finish to create the new user.

Step 3.6 - Enable e-Commerce Transaction Tracking
With some simple additions to your receipt page, Google Analytics can automatically detect and record transaction and product information. The required information is placed into a hidden form which is parsed for transaction and product information. Most template driven e-commerce systems can be modified to include this information in the receipt.
You'll also need to enable e-commerce reporting for your website's profile:
  • From the Analytics Settings page, click Edit next to the profile you would like to enable.
  • Click Edit from the Main Website Profile Information box
  • Change the E-commerce Website radio button from No to Yes.
Writing the required information
Somewhere in the receipt, below the tracking code, the following lines need to be written by your engine. Everything in brackets should be replaced by actual values, as described in
How do I track e-commerce transactions?


Gift Card and Voucher Changes in Hybris Multi-channel suite 4.8 Accelerator | Hybris 4.8 tutorial

Gift Card /Voucher Changes in Hybris Accelerator:
1.    Voucher Façade creation
•    Defining Voucher interface: Voucher interface has been defined comprising following methods
a) String redeemVoucher(String voucherCode)

b) Boolean checkVoucherCode(String voucherCode)
•    Implementing Voucher methods: Voucher methods have been implemented using CartVoucherFacadeImpl class. RedeemVoucher methods redeems voucher for given voucher code & checkvoucherCode methods check for the validity of the voucher code.
•    Spring configuration for VoucherFacade: below is the spring configuration for voucherFacade
    <!-- Added by for Voucher(Gift card) changes -->
    <bean id="cartVoucherFacade" class="se.KM.facades.voucher.impl.CartVoucherFacadeImpl" scope="tenant"/>
   
2.    Store pickup changes: Following classes have been create/updated for store pickup
a.    KMUserFacade
b.    KMAddressService
c.    KMAddressServiceImpl
d.    KMAddressDao
e.    KMAddressDaoImpl
f.    KMCustomerReviewDaoImpl
g.    MultiStepCheckoutController
h.    GiftVoucherValidator
i.    deliveryAddressDetails.tag
j.    deliveryAddressSelector.tag
k.    header.tag
l.    deliveryAddressDetails.tag
m.    deliveryAddressSelector.tag
n.    /KMstorestorefront/web/webroot/WEB-INF/tags/mobile/common/header/header.tag

•    Spring configuration for store pickup: below are the spring file changes in file KMstorecore-spring-integration.xml
    <!-- Changes done By Sachin  -->
    <!--H&M Address Service -->
    <bean id="KMAddressService" class="se.KM.core.servicelayer.user.impl.KMAddressServiceImpl" parent="abstractBusinessService" scope="tenant">
        <property name="addressDao" ref="addressDao"/>       
    </bean>
   
    <!--H&M Address DAO -->
    <alias alias="addressDao" name="KMAddressDaoImpl"/>   
    <bean id="KMAddressDaoImpl" class="se.KM.core.servicelayer.user.daos.impl.KMAddressDaoImpl" scope="tenant"/>
   
    <!--H&M Checkout Facade -->
    <!-- <alias alias="checkoutFacade" name="KMCheckoutFacade"/>
    <bean id="KMCheckoutFacade" class="se.KM.core.commercefacades.order.impl.KMCheckoutFacade" scope="tenant" parent="defaultCheckoutFacade">
        <property name="KMAddressService" ref="KMAddressService"/>
    </bean> -->
   
    <!--H&M User Facade -->
    <alias alias="userFacade" name="KMUserFacade"/>
    <bean id="KMUserFacade" class="se.KM.core.commercefacades.user.impl.KMUserFacade" scope="tenant" parent="defaultUserFacade">
        <property name="KMAddressService" ref="KMAddressService" />
    </bean>
    <!-- H&M customer review DAO- Added by SACHIN -->
    <alias alias="customerReviewDao" name="KMCustomerReviewDao"/>
    <bean id="KMCustomerReviewDao" class="se.KM.core.servicelayer.user.daos.impl.KMCustomerReviewDaoImpl" parent="defaultCustomerReviewDao" scope="tenant"/>


3.    Promotion “KM Buy X get A% discount on X” changes: Following changes have been made while defining this promotion
•    Creating Promotion:  changes have been made in /KMstorecore/resources/KMstorecore-items.xml file
            <itemtype code="KMProductBOGOFPromotion"
                extends="ProductBOGOFPromotion"
                jaloclass="se.KM.core.promotions.jalo.KMProductBOGOFPromotion"
                autocreate="true"
                generate="true" >
                <attributes>
                    <attribute
                        qualifier="percentageDiscount"
                        autocreate="true"
                        type="java.lang.Double">
                        <defaultvalue>Double.valueOf(0.0D)</defaultvalue>
                        <description>Discount on product Y</description>
                        <modifiers read="true" write="true" />
                        <persistence type="property"/>
                    </attribute>
                </attributes>
            </itemtype>
•    KMc changes: following changes have been made in KMc.xml file for front end
    <!-- Configuration for extension KMstorecore -->
    <type name="KMProductBOGOFPromotion" mode="append">
        <organizer>
            <editor mode="append">
                <tab name="tab.promotion.properties" mode="append">
                    <section name="section.promotion.products" mode="append">
                        <columnlayout leftwidth="370">
                            <row>
                                <attribute name="percentageDiscount" labelwidth="100" />
                                <text name="text.KMproductbogofpromotion.percentageDiscount" />
                            </row>
                        </columnlayout>
                    </section>
                </tab>
            </editor>
        </organizer>
    </type>
•    Changes in Jalo class: following changes have been made in jalo class in order to invoke custom evaluate method
/KMstorecore/src/se/KM/core/promotions/jalo/KMProductBOGOFPromotion.java
Following methods need to be override while defining a new promotion
    @Override
    public List<PromotionResult> evaluate(final SessionContext ctx, final PromotionEvaluationContext promoContext)
    @Override
    public String getResultDescription(final SessionContext ctx, final PromotionResult promotionResult, final Locale locale)

Explain Multi-Tenant System in Hybris e-commerce suite ? How Multi-Tenant is differ from Hybris cluster.

Multi-Tenants means individual set of data across one database .Hybris  e-commerce suite provide to run one single codebase over multiple set of data . following below point need to remember related to hybris interview point of view

1.       It provide isolation between set of data (tenant)

2.       Provide individual time zone and locale setting.

Hybris multi-Tenant is completely differ from Hybris clustering as below

A hybris Cluster is a concept different from multi-tenant hybris Commerce Suites. A hybris Cluster is a number of individual, separate hybris Commerce Suites sharing one single set of data, whereas a multi-tenant hybris Commerce Suite is one single hybris Commerce Suite using individual sets of data.

Explain extension concept in Hybris e-commerce suite. Why need extension concept in Hybris ?

Hybris e-commerce suite is based on flexible modular concept that means  hybris saying if you want to putting any new functionality then by using extension you can integrate it with hybris.. By using extgen tool you can create own extension in Hybris . Below step follow to create own extension in Hybris.

B-    Open a command prompt.

C-    Navigate to the ${HYBRIS_BIN_DIR}/platform directory.

D-    Run the ${HYBRIS_BIN_DIR}/platform/setantenv.bat file. Do not close the command prompt after this run as the settings are transient and would get lost if the command prompt is closed.

E-    Run ant extgen<ENTER> in ${HYBRIS_BIN_DIR}/platform directory. This internally runs ant in the extgen directory.

 Extgen prompts you to specify:
  •  The extension's name
  •  The extension's Java package.
  •  The extension template to use.  
  • For a list of available extension templates compatible with extgen

Need to configure below code in localextensions.xml of config folder

<path autoload="true" dir="${HYBRIS_BIN_DIR}/ext-platform"/>
<path autoload="true" dir="${HYBRIS_BIN_DIR}/ext-cockpit"/>
<path dir="${HYBRIS_BIN_DIR}"/>