Skip to main content

Google Analytics

Send survey data to Google Analytics GA4 every time a customer views or answers a question

Traian avatar
Written by Traian
Updated over 2 weeks ago

This integration in only available on the Basic and Pro plans.

Please note that this is an advanced integration which assumes you're already familiar with Google Analytics and that you have a Google Analytics account already connected to your Shopify store.

Setup in Shopify

  1. Create a new custom pixel in your Shopify dashboard by navigating to Settings > Customer Events > Custom pixels > Add custom pixel

    Navigate to Customer events > Custom pixels > Add custom pixel

  2. Choose a name for the pixel - e.g. "Google Analytics"

  3. Copy-paste the code below into the Code section. Replace G-XXXXXXXX with your Measurement ID (on line 5 and line 13), then click Connect. You can find the Measurement ID in Google Analytics, under Property settings > Data collection and modification > Data streams > Measurement ID

  (function(){
var f = document.getElementsByTagName('script')[0];
var j = document.createElement('script');
j.async = true;
j.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX';
f.parentNode.insertBefore(j, f);
})();

window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }

gtag('js', new Date());
gtag('config', 'G-XXXXXXXX');

analytics.subscribe("pathlight_question_viewed", event => {
gtag("event", "pathlight_question_viewed", {
order_id: event.customData.orderId,
customer_id: event.customData.customerId,
question_id: event.customData.questionId,
question_type: event.customData.questionType,
question: event.customData.question,
survey_id: event.customData.surveyId,
language: event.customData.language,
is_editor: event.customData.isEditor,
});
});

analytics.subscribe("pathlight_question_answered", event => {
gtag("event", "pathlight_question_answered", {
order_id: event.customData.orderId,
customer_id: event.customData.customerId,
question_id: event.customData.questionId,
question_type: event.customData.questionType,
question: event.customData.question,
answer_id: event.customData.answerId,
answer: event.customData.answer,
other_option_value: event.customData.otherOptionValue,
consent: event.customData.consent,
survey_id: event.customData.surveyId,
language: event.customData.language,
is_editor: event.customData.isEditor,
});
});

Setup Custom Dimensions

Without taking any extra steps, the pathlight_question_viewed and pathlight_question_answered events will already show up in the Google Analytics dashboard.

However, if you'd like to explore the event payloads in reports (e.g. to filter, break down and segment based on answers), we recommend setting up custom dimensions for each event parameter:

order_id
customer_id
question_id
question_type
question
answer_id
answer
other_option_value
consent
survey_id
language
is_editor

  1. Navigate to Admin > Custom definitions and click on Create custom dimensions

  2. Under Dimension name add Pathlight Answer. Under event parameter type answer. Optionally add a description, keep the scope as Event and Save.

  3. Repeat for all of the parameters you'd like to monitor or use in reporting.

Setup Segments

  1. Navigate to Admin > Segments and click on New Segment

  2. Select User segment

  3. Give the segment a name (e.g. "Instagram Customers") and click on Add new condition

  4. Choose Events > pathlight_question_answered

  5. Click on Add parameter

  6. Choose Custom > Pathlight Answer

  7. Under Condition select contains and then type the answer you'd like to match to this segment (e.g. Instagram).

You can now use this segment in your reporting and explorations. Repeat for all events, properties and answers you'd like to match.

We'd also encourage you to check out the official Google Analytics docs for more details on setting up custom dimensions and segments.

Did this answer your question?