Sunday, 15 March 2015

Media Vimeo

Download and install the following modules

  1. Media
  2. Media Internet Sources
  3. Media Vimeo
  4. enable Media Vimeo and its required Modules

Create a new content type where vimeo field will be attached

  1. enter admin page: admin/structure/types/add
  2. fill 'name' filed and save it
  3. enter admin page: admin/structure/types and click 'manage fields' of test vimeo
  4. add a field called 'test vimeo', choose 'File' as the FIELD TYPE and save the filed
  5. enter admin/structure/types/manage/test-vimeo/fields and click 'edit' of test vimeo
  6. Modify 'Allowed remote media types' and 'Allowed URI schemes' as the screenshot below
  7. enter admin/structure/types/manage/test-vimeo/display and change the FORMAT of test vimeo to 'rendered file'

Create a content of test vimeo content type

  1. enter admin/content, click 'add content' and then choose 'test vimeo' as content type
  2. click 'select media' button of 'test vimeo' field and paste the vimeo url of a video
  3. save the new content and view it

Notes

  1. Chrome bug: "SELECT MEDIA" and "REMOVE MEDIA" button can't be clicked

Enable vimeo JAVASCRIPT api (which allows us trace the embedded video)

  1. Go to D7 admin/config/media/file-types page
  2. Click the link 'manage file display' of Video
  3. Switch the bottom tab to 'Vimeo Video'
  4. Tick the check-box of 'Enable the Javascript API' and save the configuration
  5. Check a content page containing vimeo videos and notice the 'iframe' used for embedding the video. As a result, the vimeo 'player_id' which is the same as the 'iframe id' should be found in the html source code.



Google Analytics

Install the following modules

  1. Google Analytics 7.x-2.1
  2. Google Analytics Event Tracking 7.x-1.2
  3. Enable 'Google Analytics' and 'Google Analytics Event Tracking'

Install chrome extensions for debug

  1. install and configure 'Google Tag Assistant'

Set up Google Analytics account 

  1. Go to google analytics website and sign up or sign in an account : http://www.google.com/analytics/
  2. Follow the website step and go to the 'Admin/Property Settings'. The configuration is supposed to be similar as below:

    Note:  The value of 'Default URL' can be a website URL on your local computer, but it must respect the URL format, so URLs like 'http://localhost' is not allowed. In my case, I'm using 'http://drupal.localhost.com' and configure it in /etc/hosts.

Configure D7 'Google Analytics' module

  1. enter admin/config/system/googleanalytics, paster the 'Property ID' where you get from 'google analytics' on this page.
  2. enable 'internal search' tracking in the page entered by clicking 'Search and Advertising' tab on the left.
  3. toggle debug mode of this module which will output some debug information in 'chrome console' if it's on. And tick 'locally cache tracking code file' in case of downloading analytics.js from google every time visiting the website.
  4. click some links in the website and check the result on 'Google Analytics' website by accessing 'Overview' of 'Real Time' on 'Reporting' page.

    Note: 'Real-Time' is for instant tracking which is quite useful for developing and 'Audience' is for the actual website report.
  5. Pay attention that D7 'Google Analytics' is using analytics.js which is a more recent way of tracking with it's guide on the page: https://developers.google.com/analytics/devguides/collection/analyticsjs/,  while the old ga.js is still bing used by numerous developers.

Try 'Google Analytics Event Tracking' Module

  1. Enable 'Google Analytics Event Tracking Example' module which is a sample module of event tracking residing in 'Google Analytics Event Tracking'  module
  2. Open with your favourite editor the file: sites/all/modules/google_analytics_et/google_analytics_et_example/google_analytics_et_example.module
  3. Find the variable '$selectors' in the function '_google_analytics_et_example_set_selectors_array' where you put the JQuery selector and event to configure the event of the element being tracked. Below is a standard array indicating how to add them.
     array(
          'event' => 'mousedown',      //a JQuery event name
          'selector' => 'a#logo',      //a JQuery selector to figure out the specific element which will be tracked
          'category' => 'Home Link',   //Typically the object that was interacted with (e.g. button)
          'action' => 'click',         //The type of interaction (e.g. click)
          'label' => 'Logo',           //Useful for categorizing events (e.g. nav buttons)
          'value' => 0,                //Values must be non-negative. Useful to pass counts (e.g. 4 times)
          'noninteraction' => TRUE,
        ),
    // An explanation of label parameter: !textThis is what would be returned from the jQuery .text() method.!hrefThe value of the href attribute (handy with anchor //tags).!currentPageThe URL of the current page (this is taken with the code window.location.href
    //There is one more bit that is handy when configuring the module.
    //Passing !test will send an alert to the page when the event is triggered and not send the event to Google Analytics.

  4. Commentate the value of the variable $selectors and make yours
  5. Trigger the event you set up in array $selectors and enter the 'Event' tab of Goolge Analytics Real-Time page to watch the result

Tracking vimeo video in 'Google Analytics Event Tracking Example'

  1. Download vimeo.ga.js from the website: http://www.sanderheilbron.nl/vimeo.ga.js/
  2. Make sure the 'Javascript API' of 'Media: Vimeo' module is enabled referring to another wiki page: Media Vimeo
  3. Modify the file: google_analytics_et_example.module and add vimeo.ga.js in the drupal loaded Javascript list
    /**
     * Implements hook_page_alter().
     */
    function google_analytics_et_example_page_alter(&$page) {
        drupal_add_js(drupal_get_path('module', 'google_analytics_et_example') . '/js/vimeo.ga.js', array('scope' => 'footer'));
    }

  4. Open the content page containing vimeo videos and watching the 'Real-Time' event in Google Analytics.

















Form Builder

Install and enable the modules

  1. form builder: http://ftp.drupal.org/files/projects/form_builder-7.x-1.6.tar.gz
  2. Options_element: http://ftp.drupal.org/files/projects/options_element-7.x-1.12.tar.gz
  3. Enable form builder and form builder example



Add CSS classes in the div of rows of drupal view

Purpose :


add a class name called 'test-row-class' in the div of each row of drupal view

Solutions :


There are two ways to do it. First, add the class via drupal admin; Second, customize view template file named 'views-view-unformatted.tpl.php'.

Via Drupal Admin:


  1. Find the machine name of view using 'Theme Developer' module. Enable the module, click the view you want to modify on the web page, and clieck the views_view on the pop-up window of 'Theme Developer'. After that, the machine name called 'price_location' can be found in the 'candidate template files' part  
  2. Search the machine name of view in the database table of 'views_view' and get the 'human name' of view which is 'Theme Price Location Sidebar' 
  3. Go to drupal admin page of 'admin/structure/views' and search the 'human name' of view. And then click edit of the specific view. 
  4. Switch to the display block that needs to be changed  
  5. Click the 'Format: Settings' in the 'FORMAT' section  
  6. Add the class name whichever you want in the input of 'Row Class' and the class name will show up on the front page. Here using 'test-row-class' as an example. 

Via Modifying Template Files:


  1. Enable 'Theme Developer' and click the view that needs to be change on the web page  
  2. Click 'views_view_unformatted' which is the descendant of 'views_view'. ('views_view' template is the top template file, while 'views_view_unformatted' is the template file displaying the rows of the view elements). And then the candidate tmeplate files will show up. 
  3. Choose one of the candidate template files you want to use. Here will take the most specific template file name of 'views-view-unformatted--theme-price-location--theme-price-location.tpl.php'. 
  4. Create the template file in the currently used theme folder and copy the code from 'views-view-unformatted.tpl.php' which is the default template file
  5. Change the code in the specific template file as you want and it won't affect other views

Thursday, 12 March 2015

Background Image

Install and enable the modules

  1. Background Images 7.x-1.4: http://ftp.drupal.org/files/projects/bg_image-7.x-1.4.tar.gz
  2. Context 7.x-3.6: http://ftp.drupal.org/files/projects/context-7.x-3.6.tar.gz
  3. Backgroundfield 7.x-1.5: http://ftp.drupal.org/files/projects/backgroundfield-7.x-1.5.tar.gz
  4. Enable 'Context', 'Background Image', 'Background Image Context', 'Background Image UI', 'BackgroundField'

Configure 'Background Image' Module

  1. Enter D7 admin page: admin/structure/types/add, and create a new ContentType used for containing the images of background.
  2. view ContentType list and click 'manage fields' of 'background image'
  3. add an image filed which will be used to upload background images
  4. go to D7 admin page: admin/config/content/background-image
  5. select node type and node field as what we added at step 3
  6. Define the 'Selector' of CSS which by default is 'body', but we will probably change it to a specific class name whichever we want. 
  7. Attach the css 'Selector' defined at the previous step to the html tags in any of the D7 template files you want.
    Note: This is a global setting for 'Background Image' Module which will be used by 'Background Image UI' module. In 'Background Image UI' Module, we can choose different images for different pages. In order to make background image module effective,  Background Image UI must be enabled and set properly.

Set up 'Background Image UI' Module

  1. Add two nodes of 'Background Image' ContentType and upload two different images
  2. switch to 'Background Images' tab and select a background image for different pages
  3. save and browse a content page, and search the class where I'm use 'div.background-image' in the source html code.

    Note: 'Background Image' Module is good for setting a background image of the whole website or a group of web-pages. If you want to configure the background images of DIVs in the same web-page, it's better to use 'Background Field' Module.

Set up 'Background Field' Moudle

  1. Create a ContentType called 'background field' for test and add a new filed with a special type 'BackgroundField'
  2. Remember to set the CSS 'Selector' ('div.backgroundfiled' is used here) during the configuration steps of adding the new field
  3. Add a new content of 'Background Field' ContentType and search the CSS 'Selector' in the html source code
  4. You can use the CSS selector anywhere in this specific content page and it won't be found in the other content pages.

Upload Image using managed_file form api

  1. Add managed_file filed in the form containing the upload input referring to the drupal form api
  2. Add the code saving file permanently in the form submit callback function
  3. Get the URL of the uploaded file and use it

Monday, 9 March 2015

Context

  1. Download the module from the page: https://www.drupal.org/project/context, install it and enable it.
  2. Enter admin/structure/context and click 'add'
  3. Input the name of the context  
  4. Choose a condition of 'Node Type' and choose the content type of 'test'  
  5. Choose a reaction of 'Blocks' and select the blocks which are supposed to display for the contents of the content type using 'test' for instance 
  6. Click the 'Add' button of the region where the block should be put in using 'content' region as an example
  7. Browse any page of the content type and the blocks added at step 6 should show up