Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(description='Send ecommerce transactions to Google Analytics')
    parser.add_argument('--google-analytics-id', '-g', dest='google_analytics_id', default=None, help='Google Analytics ID')
    parser.add_argument('--input-file', '-i', type=argparse.FileType('r'))

    args = parser.parse_args()
    google_analytics_id = args.google_analytics_id
    input_file = args.input_file

    with input_file as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            client_id = row['client_id']
            transaction_id = row['transaction_id']
            product_name = row['product_name']
            product_price = row['product_price']
            product_quantity = row['product_quantity']
            transaction_amount = row['transaction_amount']

            print(f"client_id:{client_id} transaction_id: {transaction_id} product: {product_name}: {product_price} quantity: {product_quantity} transaction amount: {transaction_amount}")
            items = [
                enhanced_item(product_name, Money(product_price, 'USD'), quantity=product_quantity)]
            data = enhanced_purchase(transaction_id, items, Money(transaction_amount, 'USD'), '/cart/')
            report(google_analytics_id, client_id, data)
            time.sleep(0.1)
Beispiel #2
0
def test_required_params():
    items = [enhanced_item('item-01', Money(10, 'USD'))]
    generator = enhanced_purchase('trans-01', items, Money(10, 'USD'), '/cart/')
    assert list(generator) == [
        {'t': 'event', 'ec': 'ecommerce', 'ea': 'purchase'},
        {
            'pa': 'purchase', 'ti': 'trans-01', 'dp': '/cart/', 'tt': '0',
            'tr': '10', 'pr1nm': 'item-01', 'pr1pr': '10', 'pr1qt': 1}]
def main():
    parser = argparse.ArgumentParser(
        description='Send ecommerce transactions to Google Analytics')
    parser.add_argument('--google-analytics-id',
                        '-g',
                        dest='google_analytics_id',
                        default=None,
                        help='Google Analytics ID')
    parser.add_argument('--input-file', '-i', type=argparse.FileType('r'))

    args = parser.parse_args()
    google_analytics_id = args.google_analytics_id
    input_file = args.input_file

    with input_file as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            print(row)
            client_id = row['userid']
            transaction_id = ''
            product_name = 'Auction Win'
            product_price = 0
            product_quantity = row['Transactions']
            raw_transaction_amount = row['Revenue']
            transaction_amount = raw_transaction_amount.replace('$', '')
            cd1 = 'purchase'
            url = row['Landing Page']

            print(
                f"client_id:{client_id} url: {url} transaction_id: {transaction_id} product: {product_name}: {product_price} quantity: {product_quantity} transaction amount: {transaction_amount} cd1: {cd1}"
            )
            items = [
                enhanced_item(product_name,
                              Money(product_price, 'USD'),
                              quantity=product_quantity)
            ]
            data = enhanced_purchase(transaction_id,
                                     items,
                                     Money(transaction_amount, 'USD'),
                                     url,
                                     cd1=cd1)
            report(google_analytics_id, client_id, data)
            time.sleep(0.1)