### Full Regex vs. Partial Regex Example Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 Illustrates the difference between full regex (exact match) and partial regex (using metacharacters like '.*' for containing matches) in Google Analytics. ```regex San Francisco ``` ```regex .*San Francisco.* ``` -------------------------------- ### Get Client and Session IDs with gtag.js Source: https://support.google.com/analytics/answer/10071811_hl=en&ref_topic=14088998 This code snippet demonstrates how to retrieve the client ID and session ID using the `gtag('get', ...)` command. It stores these IDs in callback functions for later use, such as appending them to URLs. ```javascript gtag('get', 'TAG_ID', 'client_id', (client_id) => { // Store the client ID in a variable. }); gtag('get', 'TAG_ID', 'session_id', (session_id) => { // Store the session ID in a variable. }); ``` -------------------------------- ### Regex Metacharacter: Start of String Anchor (^) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The caret (^) anchor matches characters at the beginning of a string. This is useful for ensuring a pattern appears at the start of the text. ```regex ^ ``` -------------------------------- ### Regex Metacharacter: Wildcard (.) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The dot (.) wildcard matches any single character. This example shows its usage in matching various combinations of numbers and letters. ```regex . ``` -------------------------------- ### Regex Metacharacter: Optional (?) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The question mark (?) metacharacter matches the preceding character zero or one time. This is useful for optional elements in a pattern. ```regex ? ``` -------------------------------- ### Regex for OR Match (Multiple Cities) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 This regex pattern shows how to include campaign data from multiple specific cities using the OR operator ('|'). This allows for flexible filtering based on different location values. ```regex San Francisco|New York ``` -------------------------------- ### Google Tag (gtag.js) Snippet Source: https://support.google.com/analytics/answer/1008080 The Google tag (gtag.js) is a JavaScript snippet that needs to be pasted into the `` section of each webpage to enable data collection for Universal Analytics. This code initializes the tracking and sends data to your Analytics property. ```html ``` -------------------------------- ### Configure and Run Analytics Data Migration Script (Bash) Source: https://support.google.com/analytics/answer/7029846 This bash script automates the migration of Google Analytics event data. It requires users to configure parameters like PROPERTY_ID, BQ_PROJECT_ID, FIREBASE_APP_ID, BQ_DATASET, PLATFORM, START_DATE, and END_DATE. The script then iterates through the specified date range, constructs BigQuery table names, and executes a migration query using 'bq query', appending results to a destination table. Dependencies include 'date', 'sed', and 'bq' command-line tools. ```bash # Analytics Property ID for the Project. Find this in Analytics Settings in Firebase. PROPERTY_ID=your Analytics property ID # Bigquery Export Project. BQ_PROJECT_ID="your BigQuery Project ID" (e.g., "firebase-public-project") # Firebase App ID for the app. FIREBASE_APP_ID="your Firebase App ID" (e.g., "1:300830567303:ios:09b1ab1d3ca29bda") # Dataset to import from. BQ_DATASET="name of BigQuery dataset you want to import from" (e.g., "com_firebase_demo_IOS") # Platform PLATFORM="platform of the app. ANDROID or IOS" # Date range for which you want to run migration, [START_DATE,END_DATE] inclusive. START_DATE=20180324 END_DATE=20180327 # Do not modify the script below, unless you know what you are doing :) startdate=$(date -d"$START_DATE" +%Y%m%d) || exit -1 enddate=$(date -d"$END_DATE" +%Y%m%d) || exit -1 # Iterate through the dates. DATE="$startdate" while [ "$DATE" -le "$enddate" ]; do # BQ table constructed from above params. BQ_TABLE="$BQ_PROJECT_ID.$BQ_DATASET.app_events_$DATE" echo "Migrating $BQ_TABLE" cat migration_script.sql | sed -e "s/SCRIPT_GENERATED_TABLE_NAME/$BQ_TABLE/g" | bq query \ --debug_mode \ --allow_large_results \ --noflatten_results \ --use_legacy_sql=False \ --destination_table analytics_$PROPERTY_ID.events_$DATE \ --batch \ --append_table \ --parameter=firebase_app_id::$FIREBASE_APP_ID \ --parameter=date::$DATE \ --parameter=platform::$PLATFORM \ --project_id=$BQ_PROJECT_ID temp=$(date -I -d "$DATE + 1 day") DATE=$(date -d "$temp" +%Y%m%d) done exit # END OF SCRIPT ``` -------------------------------- ### Regex Metacharacter: Character Range [-] Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The hyphen (-) within square brackets creates a range of characters to match. For example, [0-9] matches any digit from 0 to 9. ```regex [0-9] ``` -------------------------------- ### Include Google Tag in PHP Dynamic Websites Source: https://support.google.com/analytics/answer/1008080 This PHP code snippet demonstrates how to include the Google Analytics tracking code dynamically into a PHP website. It involves placing the Google tag in a separate file and then including that file in the main template files. ```php ``` -------------------------------- ### Regex for IP Address Range Exclusion Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 This example demonstrates how to use a regular expression to exclude a range of IP addresses in Google Analytics view filters. It utilizes the wildcard character '\d' to match any digit, effectively covering the specified range. ```regex 198\.51\.100\.\d* ``` -------------------------------- ### Enable TCF Integration on Website Source: https://support.google.com/analytics/answer/10022331 This code demonstrates how to enable TCF support directly on a website by setting the `gtag_enable_tcf_support` property to `true` in the global window object. This method is applicable even for pages loaded within an iframe. ```javascript window['gtag_enable_tcf_support'] = true ``` -------------------------------- ### Device Information Structure Source: https://support.google.com/analytics/answer/12769371_hl=en&ref_topic=9359001 Details the structure for device-related data, including operating system, category, brand name, model name, and screen name. ```APIDOC ## Device Information Structure ### Description This section describes the structure and fields related to device information. ### Method GET ### Endpoint /websites/support_google_analytics/device ### Parameters #### Query Parameters - **fields** (string) - Optional - Comma-separated list of fields to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **device** (RECORD) - Device information. - **device.operating_system** (STRING) - Device operating system. - **device.category** (STRING) - Category of the device (mobile, tablet, desktop). - **device.mobile_brand_name** (STRING) - Device brand name. - **device.mobile_model_name** (STRING) - Device model name. - **device.unified_screen_name** (STRING) - Screen name. #### Response Example ```json { "device": { "operating_system": "Android", "category": "mobile", "mobile_brand_name": "Google", "mobile_model_name": "Pixel 6", "unified_screen_name": "Home Screen" } } ``` ``` -------------------------------- ### User Properties Data Structure Source: https://support.google.com/analytics/answer/12769371_hl=en&ref_topic=9359001 Details the structure for user property information, including the key, string value, and timestamp of when the value was last set. ```APIDOC ## User Properties Data Structure ### Description This section describes the structure and fields related to user-property information. ### Method GET ### Endpoint /websites/support_google_analytics/user_properties ### Parameters #### Query Parameters - **fields** (string) - Optional - Comma-separated list of fields to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **user_properties** (RECORD) - User-property information. - **user_properties.key** (STRING) - User-property dimension name. - **user_properties.value.string_value** (STRING) - User-property dimension value. - **user_properties.value.set_timestamp_micros** (INTEGER) - When the dimension value was last set (timestamp in microseconds). #### Response Example ```json { "user_properties": [ { "key": "user_tier", "value": { "string_value": "premium", "set_timestamp_micros": 1678886400000000 } } ] } ``` ``` -------------------------------- ### Regex Metacharacter: OR (|) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The pipe (|) metacharacter creates an OR match, allowing for alternatives within a regex expression. It should not be used at the end of an expression. ```regex | ``` -------------------------------- ### Regex Metacharacter: One or More (+) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The plus (+) metacharacter matches the preceding character one or more times. This is useful for patterns where a character must appear at least once. ```regex + ``` -------------------------------- ### Device Information Source: https://support.google.com/analytics/answer/7029846 The `device` RECORD contains details about the device from which an event originated, including category, brand, model, operating system, and network information. ```APIDOC ## Device Record ### Description Contains information about the device from which the event originated. ### Fields - **category** (STRING) - The device category (mobile, tablet, desktop). - **mobile_brand_name** (STRING) - The device brand name. - **mobile_model_name** (STRING) - The device model name. - **mobile_marketing_name** (STRING) - The device marketing name. - **mobile_os_hardware_model** (STRING) - The device model information retrieved directly from the operating system. - **operating_system** (STRING) - The operating system of the device. - **operating_system_version** (STRING) - The OS version. - **vendor_id** (STRING) - IDFV (present only if IDFA is not collected). - **advertising_id** (STRING) - Advertising ID/IDFA. - **language** (STRING) - The OS language. - **time_zone_offset_seconds** (INTEGER) - The offset from GMT in seconds. - **is_limited_ad_tracking** (BOOLEAN) - The device's Limit Ad Tracking setting. On iOS14+, returns false if the IDFA is non-zero. - **web_info.browser** (STRING) - The browser in which the user viewed content. - **web_info.browser_version** (STRING) - The version of the browser in which the user viewed content. - **web_info.hostname** (STRING) - The hostname associated with the logged event. ``` -------------------------------- ### Regex Metacharacter: Zero or More (*) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The asterisk (*) metacharacter matches the preceding character zero or more times. This is a versatile wildcard for matching patterns with varying occurrences. ```regex * ``` -------------------------------- ### app_info Record Source: https://support.google.com/analytics/answer/7029846 Information about the application in which the event was initiated. ```APIDOC ## app_info Record ### Description The app_info RECORD contains information about the app in which the event was initiated. ### Method N/A (Data Schema Definition) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **app_info.id** (STRING) - The package name or bundle ID of the app. - **app_info.firebase_app_id** (STRING) - The Firebase App ID associated with the app. - **app_info.install_source** (STRING) - The store that installed the app. - **app_info.version** (STRING) - The app's versionName (Android) or short bundle version. #### Response Example ```json { "app_info": { "id": "com.example.app", "firebase_app_id": "1:1234567890:android:abcdef1234567890", "install_source": "Google Play Store", "version": "1.0.0" } } ``` ``` -------------------------------- ### Regex Metacharacter: Grouping ( ) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 Parentheses () are used to group characters in an exact order or to group other expressions. This allows for complex pattern matching and structure. ```regex () ``` ```regex ([0-9]|[a-z]) ``` -------------------------------- ### BigQuery Export Schema - Datasets and Tables Source: https://support.google.com/analytics/answer/7029846 Details on how Google Analytics data is organized into datasets and tables within BigQuery. ```APIDOC ## BigQuery Export Schema ### Datasets A single dataset named `analytics_` is created for each Google Analytics property or Firebase project linked to BigQuery. The `property_id` can be found in the property settings. ### Tables - **Daily Export:** A table named `events_YYYYMMDD` is created daily if the Daily export option is enabled. - **Streaming Export:** A table named `events_intraday_YYYYMMDD` is created and populated continuously if the Streaming export option is enabled. This table is deleted at the end of the day once `events_YYYYMMDD` is complete. **Note:** Analytics updates daily tables for up to three days after the event date to account for latency. Events arriving after this window are not recorded. Sandbox users do not have intraday imports and have additional limits. ``` -------------------------------- ### Regex Metacharacter: Character Set [ ] Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 Square brackets [] match any single character within the brackets. This is useful for matching a set of possible characters. ```regex [] ``` -------------------------------- ### Configure Cross-Domain Measurement with gtag.js Source: https://support.google.com/analytics/answer/10071811_hl=en&ref_topic=14088998 This snippet shows how to configure Google Analytics on the destination domain after retrieving IDs from the URL. It uses the `gtag('config', ...)` command to set the 'client_id' and 'session_id'. ```javascript gtag('config','TAG_ID', { 'client_id': getClientIdFromUrl(), 'session_id': getSessionIdFromUrl() }); ``` -------------------------------- ### User Lifetime Value Structure Source: https://support.google.com/analytics/answer/12769371_hl=en&ref_topic=9359001 Details the structure for user lifetime value metrics, including total revenue, sessions, engagement time, purchases, and more. ```APIDOC ## User Lifetime Value Structure ### Description This section describes the structure and fields related to user lifetime value (LTV) metrics. ### Method GET ### Endpoint /websites/support_google_analytics/user_ltv ### Parameters #### Query Parameters - **fields** (string) - Optional - Comma-separated list of fields to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **user_ltv** (RECORD) - Lifetime information. - **user_ltv.revenue_in_usd** (DOUBLE) - Lifetime total revenue (in USD). - **user_ltv.sessions** (INTEGER) - Lifetime total number of sessions. - **user_ltv.engagement_time_millis** (INTEGER) - Lifetime total engagement time (in milliseconds). - **user_ltv.purchases** (INTEGER) - Lifetime total number of purchases. - **user_ltv.engaged_sessions** (INTEGER) - Lifetime total number of engaged sessions. - **user_ltv.session_duration_micros** (INTEGER) - Lifetime total session duration (in milliseconds). #### Response Example ```json { "user_ltv": { "revenue_in_usd": 150.75, "sessions": 25, "engagement_time_millis": 3600000, "purchases": 5, "engaged_sessions": 20, "session_duration_micros": 7200000000 } } ``` ``` -------------------------------- ### Regex Metacharacter: Escape (\) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The backslash (\) escapes the next character, interpreting it literally rather than as a metacharacter. This is crucial for matching special characters like dots. ```regex \ ``` ```regex \. ``` -------------------------------- ### Add Parameters to Google Analytics Ecommerce Events Source: https://support.google.com/analytics/answer/12200568 This snippet demonstrates how to add event-level and item-level parameters to an ecommerce event using the Google tag. Event-level parameters provide context about user interactions, while item-level parameters detail specific products. Ensure parameters are correctly placed outside or within the 'items' array as appropriate. ```javascript gtag("event", "view_item", { // Event-level parameters items: [ { // Item-level parameters } ] }); ``` -------------------------------- ### Regex Metacharacter: End of String Anchor ($) Source: https://support.google.com/analytics/answer/1034324_hl=en&ref_topic=14088998 The dollar sign ($) anchor matches characters at the end of a string. This is useful for ensuring a pattern appears at the termination of the text. ```regex $ ``` -------------------------------- ### Predictions Data Structure Source: https://support.google.com/analytics/answer/12769371_hl=en&ref_topic=9359001 Details the structure for prediction-related data, including scores for in-app purchase, purchase, churn, and expected revenue. ```APIDOC ## Predictions Data Structure ### Description This section describes the structure and fields related to prediction information. ### Method GET ### Endpoint /websites/support_google_analytics/predictions ### Parameters #### Query Parameters - **fields** (string) - Optional - Comma-separated list of fields to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) - **predictions** (RECORD) - Prediction information. - **predictions.in_app_purchase_score_7d** (DOUBLE) - Probability that a user who was active in the last 28 days will log an `in_app_purchase` event within the next 7 days. - **predictions.purchase_score_7d** (DOUBLE) - Probability that a user who was active in the last 28 days will log a `purchase` event within the next 7 days. - **predictions.churn_score_7d** (DOUBLE) - Probability that a user who was active on your app or site within the last 7 days will not be active within the next 7 days. - **predictions.revenue_28d_in_usd** (FLOAT) - Revenue expected (in USD) from all purchase events within the next 28 days from a user who was active in the last 28 days. #### Response Example ```json { "predictions": { "in_app_purchase_score_7d": 0.85, "purchase_score_7d": 0.70, "churn_score_7d": 0.15, "revenue_28d_in_usd": 50.25 } } ``` ``` -------------------------------- ### Enable TCF Support in Google Tags via Website Configuration Source: https://support.google.com/analytics/answer/10022331 Configures Google tags to support TCF by setting the `gtag_enable_tcf_support` global JavaScript variable to `true`. This method is a straightforward way to enable TCF integration directly on the website. No external libraries are strictly required beyond Google tags. ```javascript window['gtag_enable_tcf_support'] = true; ``` -------------------------------- ### Add Ecommerce Events to Website with Google Tag Source: https://support.google.com/analytics/answer/12200568 This snippet illustrates where to place ecommerce event tracking code within an HTML structure when using the Google tag on a website. The events can be added in the head or body sections, anywhere after the Google tag is initialized. ```html The title of the page ``` -------------------------------- ### Ecommerce Item Data Structure Source: https://support.google.com/analytics/answer/7029846 Defines the various parameters available for tracking ecommerce items, including their names, brands, pricing, quantities, and associated promotions. ```APIDOC ## Ecommerce Item Data Structure ### Description This section outlines the fields available for tracking ecommerce item details, such as name, brand, category, pricing, quantity, revenue, refunds, and promotional information. ### Method N/A (Data Structure Definition) ### Endpoint N/A (Data Structure Definition) ### Parameters #### Item Fields - **items.item_name** (STRING) - The name of the item. - **items.item_brand** (STRING) - The brand of the item. - **items.item_variant** (STRING) - The variant of the item. - **items.item_category** (STRING) - The category of the item. - **items.item_category2** (STRING) - The sub category of the item. - **items.item_category3** (STRING) - The sub category of the item. - **items.item_category4** (STRING) - The sub category of the item. - **items.item_category5** (STRING) - The sub category of the item. - **items.price_in_usd** (FLOAT) - The price of the item, in USD with standard unit. - **items.price** (FLOAT) - The price of the item in local currency. - **items.quantity** (INTEGER) - The quantity of the item. Quantity set to 1 if not specified. - **items.item_revenue_in_usd** (FLOAT) - The revenue of this item, calculated as price_in_usd * quantity. It is populated for purchase events only, in USD with standard unit. - **items.item_revenue** (FLOAT) - The revenue of this item, calculated as price * quantity. It is populated for purchase events only, in local currency with standard unit. - **items.item_refund_in_usd** (FLOAT) - The refund value of this item, calculated as price_in_usd * quantity. It is populated for refund events only, in USD with standard unit. - **items.item_refund** (FLOAT) - The refund value of this item, calculated as price * quantity. It is populated for refund events only, in local currency with standard unit. - **items.coupon** (STRING) - Coupon code applied to this item. - **items.affiliation** (STRING) - A product affiliation to designate a supplying company or brick and mortar store location. - **items.location_id** (STRING) - The location associated with the item. - **items.item_list_id** (STRING) - The ID of the list in which the item was presented to the user. - **items.item_list_name** (STRING) - The name of the list in which the item was presented to the user. - **items.item_list_index** (STRING) - The position of the item in a list. - **items.promotion_id** (STRING) - The ID of a product promotion. - **items.promotion_name** (STRING) - The name of a product promotion. - **items.creative_name** (STRING) - The name of a creative used in a promotional spot. - **items.creative_slot** (STRING) - The name of a creative slot. #### item_params RECORD The item_params RECORD stores custom item parameters not covered by predefined fields. - **items.item_params.key** (STRING) - The name of the item parameter. - **items.item_params.value** (RECORD) - A record containing the item parameter’s value. - **items.item_params.value.string_value** (STRING) - Value if the parameter is a string. - **items.item_params.value.int_value** (INTEGER) - Value if the parameter is an integer. - **items.item_params.value.double_value** (FLOAT) - Value if the parameter is a double. - **items.item_params.value.float_value** (FLOAT) - Value if the parameter is a float. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Item Parameters Source: https://support.google.com/analytics/answer/7029846 The `item_params` RECORD stores item-specific parameters and custom user-defined parameters. The structure of these parameters is unique to each implementation. ```APIDOC ## item_params RECORD ### Description Stores item parameters and any user-defined item parameters. The set of parameters stored is unique to each implementation. ### Fields - **key** (STRING) - The name of the item parameter. - **value** (RECORD) - A record containing the item parameter’s value. - **value.string_value** (STRING) - Populated if the item parameter is a string. - **value.int_value** (INTEGER) - Populated if the item parameter is an integer. - **value.double_value** (FLOAT) - Populated if the item parameter is a double value. - **value.float_value** (FLOAT) - Populated if the item parameter is a floating point value. ```