### 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_