If you’re trying to set up custom Olark events inside of Google Analytics or if you’re having problems with the Analytics integration provided by Olark then this script will let you replace the stock integration and have more control over when and what triggers the events.
Inside of Google Analytics, you will see no difference. The script is set up to replace the stock Olark to Google Analytics integration and thus will display the same event categories and actions inside of Google Analytics.
Set Up
This script assumes you’re using Google Tag Manager (GTM) and that Google Analytics is set up via GTM.
Step 1
Create a new GTM variable and name it “event_action” with the following settings:
Variable Type: Data Layer Variable
Variable Name: event_action
Step 2
Create a Tag titled “Olark Listener” (or whatever fits your schema). This tag will listen to the script and send the event information to the GTM variable you created in step 1.
For the tag type use “Custom HTML”. Copy and Paste this html code into the code block inside of the “Custom HTML” tag you just made. Make sure to include <script> and </script> when you copy the code!
For the tag trigger, with a standard set up, use “All Pages”.
Your tag should now look like this:
Step 3
Now, create a 2nd tag and call it “Olark Event Tracker”. This tag will take the information that the “Olark Listener” (Step 2) tag sends to the data layer and send it to Google Analytics.
Step 3a
Set up the tag with the following settings:
Tag Type: Google Analytics: Universal Analytics
Track Type: Event
Category: Olark_Chat
Action: {{event_action}}
The tag should now look like this:
Step 3b
For this tag’s trigger, use trigger type “Custom Event” and name it “Olark Analytics Listener”.
Set up this tag trigger with the following settings:
Event name: Olark_Chat_C
This trigger fires on: Some Custom Events
Conditions: Event | equals | Olark_Chat_C
The trigger configuration should now look like this:
Step 4
Testing time!
Put Google Tag Manager into preview mode and pull up the “events” subpage in the Realtime section of Google Analytics.
Open and close your Olark chat box and you should now see yourself triggering the “Olark Chat” event. Select “Event Action” to confirm that the event action is sending the correct message, which should be “Vistor_Expanded_Olark”.
All done! Let us know what you think of this tutorial using the comment section or contact form below or via the live chat box!